Pandas read_csv dtype leading zeros

前端 未结 5 444
再見小時候
再見小時候 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

    With Pandas 1, how about:

    df.read_csv(..., dtype={"my_confusing_col": "string"})
    

    Note that will use the column dtype string which uses pd.NA for any missing values. All leading zeros will of course be preserved.

提交回复
热议问题