Having trouble converting datetime entries to month values over 3 columns in my dataframe.
What i have tried is writing a lambda function:
lambda x: x.strftime('%m') if isinstance(x , datetime.datetime) else x
and using .apply to apply it:
df.apply(lambda x: x.strftime('%m') if isinstance(x , datetime.datetime) else x)
I seem to be getting no change to my dataset.
desired outcome is to go from this:
| date 1 | date 2 | date 3 |
|---|---|---|
| 2022-05-26 00:00:00 | 2022-05-31 00:00:00 | 2022-06-05 00:00:00 |
| 2022-06-01 00:00:00 | 2022-06-13 00:00:00 | 2022-07-05 00:00:00 |
to this:
| date 1 | date 2 | date 3 |
|---|---|---|
| 05 | 05 | 06 |
| 06 | 06 | 07 |