pandas read_csv将列转换为int类型

时间:2017-03-04 08:00:51

标签: python pandas

我下载了一个csv,当我读取数据时,它打印出'Volume'列为:

0     623,446,600
1     371,965,300
2     260,752,300
3     116,561,400
Name: Volume, dtype: object

如何将其更改为dtype: int

我尝试更换,,但我不确定它是如何完成的。

1 个答案:

答案 0 :(得分:3)

我认为您需要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
相关问题