Pandas 0.8 read_csv无法识别'dtype'参数

时间:2013-06-04 22:08:19

标签: python pandas csv types

我正在尝试使用dtype参数使用pandas(0.8.1)读取csv文件并且出错。

我的csv文件结构如下所示:

"USAF","WBAN","STATION NAME","CTRY","FIPS","STATE","CALL","LAT","LON","ELEV(.1M)","BEGIN","END"
"006852","99999","SENT","SW","SZ","","","+46817","+010350","+14200","",""
"007005","99999","CWOS 07005","","","","","-99999","-999999","-99999","20120127","20120127"

我需要指定dtype的原因是因为前两列USAFWBAN需要是字符串,因为它们有时以零开头,而当我经常阅读时它会转换为0006852之类的数字这是我正在使用的代码:

import pandas as pd
df = pd.io.parsers.read_csv("Station Codes.csv", dtype={'USAF': np.str, 'WBAN': np.str})

导致以下错误:

TypeError: read_csv() got an unexpected keyword argument 'dtype'

当我在这里看到文档时,我不明白为什么它说它是一个意想不到的关键字参数: http://pandas.pydata.org/pandas-docs/dev/generated/pandas.io.parsers.read_csv.html

我在这里错过了什么吗?

1 个答案:

答案 0 :(得分:3)

dtype参数为introduced in 0.10 升级到the latest stable release以获取最新和最强大的功能以及错误修复。