I have the following dataframe, in which col_1 is type integer:
print(df)
col_1
100
200
00153
00164
I would like to add two zeros, if the number of digits is equal to 3:
final_col
00100
00200
00153
00164
I tried with:
df.col_1 = df.col_1.astype(int).astype(str)
df["final_col"] = np.where(len(df["col_1"]) == 3, "00" + df.col_1, df.col_1 )
But it doesn't produce the expected output (it doesn't add the two digits when the condition is satisfied).
How can I solve that?