Issue
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
Solution
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()
Answered By - HedgeHog
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.