I am trying to add a day to my column CutoffSLAII if the time in the column is after 1.59am, however, I only want to add a day if the column FILE_START_TIME also has a time prior to 12:00am. If neither of these conditions are met, then the value in CutoffSLAII should be retained.
The code I am using does run, but nothing changes in the dataframe:
from datetime import datetime, time, timedelta import pandas as pd
def add_a_day(row: pd.Series) -> datetime:
if pd.isna(x['CutoffSLAII', 'FILE_START_TIME']):
return x['CutoffSLAII', 'FILE_START_TIME']
tme = x['CutoffSLAII'].time()
tme1 = x['FILE_START_TIME'].time()
if tme < time(12, 0, 0) and tme1 > time(1, 59, 0):
return x['CutoffSLAII'] + timedelta(days=1)
data: df2['CutoffSLAII'] = df2.apply(add_a_day, axis=1)
Data that I wish to add a day to:
Both FILE_START_TIME and CutoffSLAII are Datetime64[ns] dtypes, however, when I interact with one value in the columns, they are returned as a timestamp.
in: df2.iloc[0]['FILE_START_TIME']
out: Timestamp('2020-11-02 19:23:47')
The data is not embedded as I do not have enough reputation points, sorry for that.
The error message is now:
TypeError: string indices must be integers