I have a imported a time series csv file into a pandas DataFrame, however there is a quirk in the time from the file. Midnight is set as '24:00:00', not '00:00:00' (which is how pythons datetime likes it).
To create a datetime column in pandas I've done the following (both 'Date' and 'Time' are strings):
df['Date and Time'] = pd.to_datetime(df['Date'] + ' ' + df['Time'])
However, datetime requires the hour of time to be between 0 and 23. I can replace '24:00:00' to '00:00:00' with:
df['Time'].replace('24:00:00', '00:00:00', inplace = True)
But then this in fact the morning of that day, not the night. Ideally I would then add a day to the date except I can't work out how to do this. I want to say "Where 'Time' == '00:00:00' add one day onto the date". I've tried something like this:
df['Date and Time'][df['Time'] == '00:00:00'] = df['Date and Time'[df['Time'] == '00:00:00'] + timedelta(days = 1)
But that doesn't work (and looks horrible).
Any ideas how I can get this to work?
Thanks!