我下载了一个 csv,当我读取数据时,它打印出了 'Volume'
列:
0 623,446,600
1 371,965,300
2 260,752,300
3 116,561,400
Name: Volume, dtype: object
如何将其更改为 dtype: int
?
我尝试替换,
,但我不确定它是如何完成的。
最佳答案
我认为您需要 read_csv
中的参数 thousands=','
.
示例:
import pandas as pd
from pandas.compat import StringIO
temp=u"""Volume
0;623,446,600
1;371,965,300
2;260,752,300
3;116,561,400
"""
#after testing replace 'StringIO(temp)' to 'filename.csv'
df = pd.read_csv(StringIO(temp), sep=";", thousands=',')
print (df)
Volume
0 623446600
1 371965300
2 260752300
3 116561400
print (df.dtypes)
Volume int64
dtype: object
关于python - pandas read_csv 将列转换为 int 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42593666/