vlad
vlad

Reputation: 49

modify a spacial format date pandas dataframe

I am new using pandas and i have this dataframe

| colDat      |
| 09 Mar 2021 |
| 09 Feb 2021 |

I want to add a new column to convert the format date :

| colDat      | newColDat |
| 09 Mar 2021 | 2021-03-09T00:00:00.0000|
| 09 Feb 2021 | 2021-02-09T00:00:00.0000|

thank you for your help

Upvotes: 0

Views: 17

Answers (1)

CFreitas
CFreitas

Reputation: 1775

To convert your date to ISO format, assuming the initial column is text:

df['newColDat'] = df.colDat.apply(lambda x: pd.to_datetime(x).isoformat()+'.0000')

Result:

    colDat      newColDat
0   09 Mar 2021 2021-03-09T00:00:00.0000
1   09 Feb 2021 2021-02-09T00:00:00.0000

Upvotes: 1

Related Questions