4

我正在尝试使用 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 之类的数字转换为 6852。这是我正在使用的代码:

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

我在这里错过了什么吗?

4

1 回答 1

3

dtype论点是在 0.10 中引入的
升级到最新的稳定版本以获得最新和最强大的功能和错误修复。

于 2013-06-04T22:20:45.693 回答