代码:
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)
我试图为cols
(它们是float64
)中的列插入缺少的数据,但是我一直得到以下错误:
TypeError: unsupported operand type(s) for /: 'str' and 'float'
这是没有意义的,因为我的列是float
格式的,并且是数字。我是否需要首先通过执行以下操作将这些列转换为 int
:
who[cols] = who[cols].apply(lambda x: x.interpolate(method="nearest"), axis=1).astype(int)
目前没有回答
相关问题 更多 >
编程相关推荐