I load data to dataframe:
dfzips = pd.read_excel(filename_zips, dtype='object')
Dataframe has column with value: 00590
After load dataframe I got this as 590
.
I have tried dtype='object'
. Does not help me.
Advertisement
Answer
Have you tried using str instead of object? if you use str (string) it maintains the zeros at the beginning.
It could be good to specify the column name you would like to change to str or object (without quotations).
1)
dfzips = pd.read_excel(filename_zips,dtype=str)
It even supports this a dict mapping where the keys constitute the column names and values the data types to be set when you want to change it. You didnt specify the column name so i just put it as “column_1”
dfzips = pd.read_excel(filename_zips,dtype={"column_1":str})