TypeError: unsupported operand type(s) for /: 'str' and 'float' when trying to pass interperpolate
08:43 10 Oct 2020

Code:

cols = ["e_tbhiv_prct", "e_tbhiv_prct_lo", "e_tbhiv_prct_hi", "e_inc_tbhiv_100k", "e_inc_tbhiv_100k_lo",
       "e_inc_tbhiv_100k_hi", "e_inc_tbhiv_num", "e_inc_tbhiv_num_lo", "e_inc_tbhiv_num_hi"]

who[cols].apply(pd.to_numeric)

who[cols].interpolate(method="nearest", axis=1)

I'm trying to interpolate missing data for the columns in cols (which are float64) however I keep getting the following error:

TypeError: unsupported operand type(s) for /: 'str' and 'float'

which doesn't make sense given my columns are in the float format and are numeric. Do I need to transform these columns into int first by executing something like:

who[cols] = who[cols].apply(lambda x: x.interpolate(method="nearest"), axis=1).astype(int)
python pandas interpolation