I am using python 3.
I have a column of decimal numbers called “CIPCODE” in a dataframe called “data”. The integer part of this column ranges from 1 to 60.
I want to format it such that:
the first condition is: if the value of the integer part is between 1 and 9 (inclusive), then add a zero in front of the number, for example -
4.2021 becomes 04.2021
25.3434 remains 25.3434
so basically, we should always have 2 digits before the decimal.
the second condition is: that there should always be 4 digits after the decimal, for example -
51.201 becomes 51.2010
34.5555 remains 34.5555
I have tried the following:
data['CIPCODE'] = data['CIPCODE'].astype(str).str.zfill(7)
but this only pads zeros to the part before the decimal point.