![](/img/trans.png)
[英]string formatting error when trying to multiply tuple elements - python
[英]Error when trying to multiply a variable?
我正在嘗試將一個變量乘以 output 一個加權值,如下所示:
import numpy as np
import pandas as pd
data_2017_18.income1_weight = data_2017_18.income1 * data_2017_18.survey_weight
我收到以下錯誤消息:
TypeError: Object with dtype category cannot perform the numpy op multiply
我嘗試將 data_2017_18.income1 更改為 integer,如下所示:
int(data_2017_18.income1)
但我收到此錯誤:
類型錯誤:無法將系列轉換為 <class 'int'>
有什么建議嗎?
非常感謝
嘗試Series.astype
:
data_2017_18.income1_weight = data_2017_18.income1.astype(float) * data_2017_18.survey_weight
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.