因此,我在dataframe中有一个列,其中充满了浮点值和偶尔的字符串值。我试过在堆栈上跟踪一些答案,但它只是不起作用。
print(data['Snowfall'][48609]) #prints #VALUE!
print(type(data['Snowfall'][48609])) #prints <class 'str'>
data['Snowfall'].str.contains("#VALUE!").replace(float(0.0),inplace=True)
print(type(data['Snowfall'][48609])) # prints <class 'str'>我做错什么了
发布于 2018-10-01 15:39:07
使用pandas.to_numeric将‘胁迫’传递给errors参数。然后Series.fillna将强制值更改为0
df['Snowfall'] = pd.to_numeric(df['Snowfall'], errors='coerce').fillna(0)https://stackoverflow.com/questions/52594458
复制相似问题