Jan-05-2021, 05:56 PM
Hi guys,
I have a pandas generated dataframe (df) where the first column has a series of dates as below:
If I look at the raw values in the df array:
This code gives this output:
Copying back the re-formatted dates to the df:
Any ideas please?
I have a pandas generated dataframe (df) where the first column has a series of dates as below:
Output:0 11.26.2020 03:36
1 12.01.2020 15:00
2 12.01.2020 21:30
3 12.02.2020 13:26
4 12.04.2020 22:43
5 12.21.2020 00:05
I need to change these dates to a format YY,MM,DD H:MIf I look at the raw values in the df array:
df.values[:,0]
Output:array(['11.26.2020 03:36', '12.01.2020 15:00', '12.01.2020 21:30',
'12.02.2020 13:26', '12.04.2020 22:43', '12.21.2020 00:05'],
dtype=object)
We need to change these values to a DateTimeIndexArray and then parse to the correct string format:dti = pd.to_datetime(df.values[:,0]) dti = dti.strftime('%Y.%m.%d %H:%M') dti.values
This code gives this output:
Output:array(['2020.11.26 03:36', '2020.12.01 15:00', '2020.12.01 21:30',
'2020.12.02 13:26', '2020.12.04 22:43', '2020.12.21 00:05'],
dtype=object)
So it looks like it's done what I want!Copying back the re-formatted dates to the df:
df.values[:,0] = dti.valuesThis does not work! The dates remain in the original format.
Any ideas please?