I have a table as shown below.
id name
010014 messi
092754 ronaldo
864287 benzema
K26541 xavi
When I load above table as pandas data frame, the leading zeros in the id
column disappears. How can I avoid that.
Data after loading the table as pandas data frame
id name
10014 messi
92754 ronaldo
864287 benzema
K26541 xavi
CodePudding user response:
One approache would be to set the dtype
for your column to str
:
df = pd.read_table(yourdata, dtype = {'id': str})
This will also work for pandas.read_csv()
or pandas.read_excel()