简体   繁体   English

尝试乘以变量时出错?

[英]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.

相关问题 尝试乘以元组元素时字符串格式错误 - python - string formatting error when trying to multiply tuple elements - python 尝试将 function 参数乘以 integer 时出现不支持的操作数类型错误 - Unsupported operand type error when trying to multiply function parameter by an integer 尝试将浮点数与 len(list) 相乘时,无法将序列乘以“float”类型的非整数错误 - can't multiply sequence by non-int of type 'float' ERROR when trying to multiply a float number with len(list) 当尝试在循环中乘以矩阵元素时,错误“只有长度为1的数组可以转换为Python标量”? - The error “only length-1 arrays can be converted to Python scalars” when trying to multiply matrix elements within a loop? 尝试插入变量时出错 - Getting error when trying to interpolate variable pytorch乘以4 * 1矩阵和1大小变量发生错误 - pytorch multiply 4*1 matrix and 1 size variable occur error Python:尝试调用函数时出现未定义变量错误? - Python: Getting an undefine variable error when trying to call a function? 尝试从类的函数中打印变量时在 python 中出错 - Getting error in python when trying to print a variable from a class' function 尝试将NN定义为类时初始化tf.variable时出错 - Error in initializing a tf.variable when trying to define the NN as a class 在一个视图中尝试多格式时出现局部变量错误 - local variable error when trying multiform in one view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM