[英]Error when trying to multiply a variable?
I'm trying to multiply a variable to output a weighted value as follows:我正在尝试将一个变量乘以 output 一个加权值,如下所示:
import numpy as np
import pandas as pd
data_2017_18.income1_weight = data_2017_18.income1 * data_2017_18.survey_weight
I'm receiving the following error message:我收到以下错误消息:
TypeError: Object with dtype category cannot perform the numpy op multiply TypeError: Object with dtype category cannot perform the numpy op multiply
I've tried to change the data_2017_18.income1 to an integer as follows:我尝试将 data_2017_18.income1 更改为 integer,如下所示:
int(data_2017_18.income1)
But I'm getting this error:但我收到此错误:
TypeError: cannot convert the series to <class 'int'>类型错误:无法将系列转换为 <class 'int'>
Any suggestions, please?有什么建议吗?
Many thanks非常感谢
Try Series.astype
:尝试
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.