aditya royal matturi
aditya royal matturi

Reputation: 111

how to add zero before a number if the number is less than 10 in a dataframe column

I had a column in data frame and I wanted to convert each value in the column cpro to a two digit number by adding '0' in front of it if the number is less than 10. I had done it in the following way '0'.join(df.loc[df['cpro']<10,'cpro'].astype(str).tolist())

Upvotes: 1

Views: 1153

Answers (1)

Yimin Rong
Yimin Rong

Reputation: 2027

Where x is the string to pad:

x.zfill(2)

Upvotes: 1

Related Questions