Is there an efficient way to add leading zeroes to a Dataframe's columns if:
- The column contains integer values, and
- For a given value of another column in the same Dataframe
E.g. for the following Dataframe, how do I create a new DataFrame that has leading zeroes in values in col_2 if:
col_2are integer values (i.e. not"text"nor"text2")col_1 == "A"
Initial Dataframe:
col_1 col_2
0 A 12345
1 B 863
2 A text
3 C 893423
4 D text2
Desired output Dataframe:
col_1 col_2
0 A 00012345
1 B 863
2 A text
3 C 893423
4 D text2