Pandas read_csv dtype leading zeros

前端 未结 5 461
再見小時候
再見小時候 2020-11-29 10:45

So I\'m reading in a station codes csv file from NOAA which looks like this:

\"USAF\",\"WBAN\",\"STATION NAME\",\"CTRY\",\"FIPS\",\"STATE\",\"CALL\",\"LAT\",         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 11:20

    You can pass a dictionary of functions to converters where the keys are numeric column indices. So, if you don't know what your column names will be, you can do this (provided you have less than 100 columns).

    pd.read_csv('some_file.csv', converters={i: str for i in range(100)})

提交回复
热议问题