Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python dataframe列中的值不会从字符串更改为浮点值_Python_Pandas - Fatal编程技术网

Python dataframe列中的值不会从字符串更改为浮点值

Python dataframe列中的值不会从字符串更改为浮点值,python,pandas,Python,Pandas,所以我在数据框中有一列,其中填充了浮点值和偶尔的字符串值。我试着在堆栈上找到一些答案,但就是不起作用 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(da

所以我在数据框中有一列,其中填充了浮点值和偶尔的字符串值。我试着在堆栈上找到一些答案,但就是不起作用

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'>
print(数据['Snowfall'][48609])#prints#值!
打印(类型(数据['Snowfall'][48609])#打印
数据['Snowfall'].str.contains(“#VALUE!”).replace(float(0.0),inplace=True)
打印(类型(数据['Snowfall'][48609])#打印
我做错了什么

使用将“强制”传递给
errors
参数。 然后将强制值更改为
0

df['Snowfall'] = pd.to_numeric(df['Snowfall'], errors='coerce').fillna(0)
您可能需要
df.astype()