我正在尝试使用 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 的原因是因为前两列需要是字符串USAF
,WBAN
因为它们有时以零开头,并且当我定期阅读时,它会将 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
我在这里错过了什么吗?