2013-06-04 167 views
4

我想讀取一個csv文件使用熊貓使用dtype參數,並有一個錯誤。熊貓read_csv使用dtype

我的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" 

我之所以需要指定D型是因爲前兩列有時用零開始,當我定期閱讀其轉換像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

我失去了一些東西在這裏?

+0

你使用的是什麼版本的熊貓? –

回答

3

dtype的論點是introduced in 0.10
升級到the latest stable release以獲得最新和最好的功能和錯誤修復。

+0

非常感謝,我在0.8.1上。仍然不喜歡np.str,但這是另一個問題:/ –

+0

我試過了,仍然得到相同的錯誤。新問題在這裏:http://stackoverflow.com/questions/16929056/pandas-read-csv-dtype-leading-zeros –