how to add zeros in front of numbers in pandas 1

how to add zeros in front of numbers in pandas

number = 15 # number of zeroes to add
df['ID'] = df['ID'].str.zfill(number)

Here is what the above code is Doing:
1. We create a new column called ‘ID’ and set it equal to the ‘ID’ column.
2. We use the .str method to tell Python that we want to apply a string method to the column.
3. We use the .zfill method to tell Python that we want to add zeroes to the beginning of the string.
4. We set the number of zeroes to add equal to the variable number.

Similar Posts