I am trying to calculate machine downtime in a python code which is predominantly pandas dataframe manipulation. If a repair number starts during any of the days then I have take take time bewteen start of the day and start of the work order as my machine available time. I have created the column for day start time as in every row which is at a day level granularity so that when there is a repair order I just need to subtract two time fields to get my answer in seconds/hours. But I am currently getting error as 'Timedelta' object has no attribute 'astype'. I tried out of a few options suggested here but to no vail. I know I am doing somehting very fundamentally wrong, please point me in the right directions.
for i, row in df4.iterrows():
if (row['Date'] == row['START_DATE']) | (row['Date'] == row['END_DATE']):
if (row['START_DATE'] == row['Date']) & (row['END_DATE'] != row['Date']):
value = pd.to_timedelta(row.REPAIR_START-row.Date_start).astype('timedelta64[h]')
df4.set_value(i,'avail',value)
if (row['START_DATE'] != row['Date']) & (row['END_DATE'] == row['Date']):
value = pd.to_timedelta((row.REPAIR_FINISH-row.Date_end)).astype('timedelta64[h]')
df4.set_value(i,'avail',value)
if (row['START_DATE'] == row['Date']) & (row['END_DATE'] == row['Date']):
value = pd.to_timedelta((row.REPAIR_START-row.REPAIR_FINISH)).astype('timedelta64[h]')
df4.set_value(i,'avail',value)
else: df4.set_value(i,'avail',full_day)
Data is at Machine , Date level. Explanation of the metadata of the code:
Date : Daily date
START_DATE : Only date part of the repair timestamp
END_DATE : Only date part of the repair timestamp
REPAIR_START : Repair order start timestamp
REPAIR_START : Repair order end timestamp