Hi whoever is reading this! I am attempting to use df['ride_duration'] = df['ride_duration'].replace(r'^\s+$',"00:00:00", regex=True)
to remove whitespaces/blanks from the screenshot attached below. Thing is, for some reason this is not working even though this is what I found from looking around on Stack Overflow. I Also tried: df['ride_duration'] = df['ride_duration'].replace("","00:00:00)
The Result unfortunately does not change the column at all. Could someone please point me in the right direction of why this is not working?
Sample code:
fmtymd = '%Y/%m/%d'
df = pd.read_csv(csvfilelocation, sep=',')
df['scheduled departure time'] = pd.to_datetime(df['scheduled departure time'], format = fmtymd)
df['epoch_arrival'] = pd.to_datetime(df['epoch_arrival'], format = fmtymd)
df['latetime'] = (df['epoch_arrival'] - df['scheduled departure time']).where(df['OTP'] == False)
df['latetime'] = df['latetime'].replace("","00:00:00")
df['latetime'] = pd.to_timedelta(df['latetime'])
df['latetime'] = (df['latetime'] / np.timedelta64(1, 'm')).astype(int)
df.to_csv(csvfilelocation, index=False, float_format='%.0f')
CSV Sample: https://ufile.io/qtkxb