Pandas read_csv using dtype

I am trying to read a csv file using pandas using the dtype parameter and have an error.

My csv file structure is as follows:

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

The reason I need to specify dtype is because the first two columns sometimes start with zeros, and when I read regularly, it converts the number, for example 0006852, to 6852. Here is the code that I use:

 import pandas as pd df = pd.io.parsers.read_csv("Station Codes.csv",dtype={'USAF': np.str, 'WBAN': np.str}) 

leads to the following error:

 TypeError: read_csv() got an unexpected keyword argument 'dtype' 

I don't understand why he says his unexpected keyword argument when I see the documentation here: http://pandas.pydata.org/pandas-docs/dev/generated/pandas.io.parsers.read_csv.html

Did I miss something?

+4
source share
1 answer

The dtype argument was introduced at 0.10 .
Update the latest stable version for the latest and greatest features and bug fixes.

+3
source

Source: https://habr.com/ru/post/1484519/


All Articles