gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:54 26 4
gpt4 key购买 nike

我正在尝试使用 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

我是不是漏掉了什么?

最佳答案

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

关于python - Pandas 0.8 read_csv 无法识别 'dtype' 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16928339/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com