I'm trying to multiply a variable to output a weighted value as follows:
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
I've tried to change the data_2017_18.income1 to an integer as follows:
int(data_2017_18.income1)
But I'm getting this error:
TypeError: cannot convert the series to <class 'int'>
Any suggestions, please?
Many thanks
Try Series.astype
:
data_2017_18.income1_weight = data_2017_18.income1.astype(float) * data_2017_18.survey_weight
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.