I have a excel file and I read into a dataframe. I'd like to output this df to CSV file. But one of the columns (labeled id
) in CSV file are integer like 1 ,but wanna output string like"0001"with leading zeros.
Every time I try to output the file, it interprets this column as integer and removes the leading zeros. I need all leading zeros.
I've tried
import pandas as pd
df = pd.read_excel(<path&filenane>,convertors={"id":object})
df.to_csv(<path&filename>)
CSV file I'd like to see
id,name,birthday
0001,smith,1980/01/01
dtypes =object,object,object
But now
id,name,birthday
1,smith,1980/01/01
dtypes=int,object,object