导入csv时,pandas无法识别浮点数列
发布于 2021-01-29 16:18:34
我正在尝试将IMF统计信息读入pandas数据框:
import pandas as pd
df = pd.read_table("http://www.imf.org/external/pubs/ft/weo/2013/02/weodata/WEOOct2013all.xls",
na_values=['n/a','--'],thousands=',')
除一列外,所有列均具有dtype对象:
In [5]: df
Out[5]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 8318 entries, 0 to 8317
Data columns (total 49 columns):
...
dtypes: float64(1), object(48)
我手动检查了该文件,但在大多数列中找不到任何不是数字的值或代码中明确提到的NaN值之一。
我在Wakari.io的Anaconda 1.5.0上使用Python 2.7.5,numpy 1.7.1,pandas 0.11.0。
关注者
0
被浏览
51
1 个回答
-
如Jeff所述,这是<=
0.12的错误(但已在0.13中修复)。In [11]: s = '''A;B 1;2,000 3;4''' In [12]: pd.read_csv(StringIO(s), sep=';', thousands=',') Out[12]: A B 0 1 2000 1 3 4 [2 rows x 2 columns] In [13]: pd.version.version Out[13]: '0.13.0rc1-82-g66934c2'