![](/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.