![](/img/trans.png)
[英]AttributeError("module 'pandas' has no attribute 'read_csv'")
[英]Pandas read_csv: AttributeError: 'NoneType' object has no attribute 'dtype'
假设我有一个文件test.csv,如下所示:
A,B,C
Hello,Hi,1
我正在尝试将其读入Pandas数据框:
cols = ['A','B','C']
col_types = {'A': str, 'B': str, 'C': int}
test = pd.read_csv('test.csv', names=cols, dtype=col_types)
这会产生错误
AttributeError: 'NoneType' object has no attribute 'dtype'
有任何想法吗?
您的文件已包含标题行,因此无需指定任何名称 。
In [6]: test = pd.read_csv('test.csv', dtype=col_types)
In [7]: test
Out[7]:
A B C
0 Hello Hi 1
In [8]: test.dtypes
Out[8]:
A object
B object
C int64
dtype: object
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.