0

I have a data frame contains the information of some ids.

df  
    ID
0   34
1   756
2   1090
3   3
4   45
5   549020

I would like to add some zeros before each ids in order to get ids of 8 digits, in order to get:

df  
    ID
0   00000034
1   00000756
2   00001090
3   00000003
4   00000045
5   00549020
3
  • Use df['ID'] = df['ID'].str.zfill(8)
    – jezrael
    Jul 19, 2018 at 8:01
  • @jezrael should I convert the values as strings?
    – emax
    Jul 19, 2018 at 8:10
  • 1
    Yes, try df['ID'] = df['ID'].astype(str).str.zfill(8)
    – jezrael
    Jul 19, 2018 at 8:13

0

Browse other questions tagged or ask your own question.