创建 DataFrame 时指定类型,直接通过 dtype 参数指定类型
df里非数字类型的字段不会转成数字
str仍保留为str
df = pd.DataFrame(positions['data'], dtype=float)
2、单列series转为数字
pd.to_numeric(s) # or pd.to_numeric(s, errors='raise');
3、多列或者整个 DataFrame
df[['col2','col3']] = df[['col2','col3']].apply(pd.to_numeric)
df.dtypes