import pandas as pd df = pd.DataFrame([['11.0' ,1,2,3], ['22.0' ,4,5,6], ['33.0' ,7,8,9]], columns = ['a','b','c','d'])
df['a'] = pd.to_numeric(df['a'],errors = 'coerce')
列 a
的类型,是 object
类型。 pd.to_numeric()
将这个对象转换为 float
errors=coerce 将不能转换的字符替换为空值: NaN