How do I replace specific times in pandas column that is datetime format? I need to replace all times of 23:52:00 with 23:59:59 in df.end
data = [['site a', '2021-03-05 23:52:00'],
['site a', '2021-03-06 12:00:00'],
['site b', '2021-04-08 23:00:00'],
['site c', '2021-04-09 23:52:00']]
df = pd.DataFrame(data, columns = ['id', 'end'])
df['end'] = pd.to_datetime(df['end'], infer_datetime_format=True)
Using this where statement, none of the times change. this due to this statement: df['end'].dt.time == '23:52:00'
np.where(df['end'].dt.time == '23:52:00', (df['end'].dt.normalize() + pd.Timedelta('23:59:59')), df['end'])
Out[74]: array(['2021-03-05T23:52:00.000000000', '2021-03-06T12:00:00.000000000',
'2021-04-08T23:00:00.000000000', '2021-04-09T23:52:00.000000000'],
dtype='datetime64[ns]')