I have a datarframe with a DatetimeIndex, and want to add a column with the day to my df.
My code df.loc[:,'Day'] = df.index.date
gives the error
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
How do I do this with the index?
EDIT Below is my index
df.index
>> DatetimeIndex(['2022-05-23 03:00:02+02:00', '2022-05-23 03:00:13+02:00',
'2022-05-23 03:00:23+02:00', '2022-05-23 03:00:33+02:00',
'2022-05-23 03:00:43+02:00', '2022-05-23 03:00:53+02:00',
'2022-05-23 03:01:03+02:00', '2022-05-23 03:01:13+02:00',
'2022-05-23 03:01:23+02:00', '2022-05-23 03:01:33+02:00',
...
'2022-05-24 21:58:29+02:00', '2022-05-24 21:58:39+02:00',
'2022-05-24 21:58:49+02:00', '2022-05-24 21:58:59+02:00',
'2022-05-24 21:59:09+02:00', '2022-05-24 21:59:19+02:00',
'2022-05-24 21:59:29+02:00', '2022-05-24 21:59:39+02:00',
'2022-05-24 21:59:49+02:00', '2022-05-24 21:59:59+02:00'],
dtype='datetime64[ns, Europe/Stockholm]', name='Timestamp', length=13758, freq=None)