Home > Software design >  Find truck name and sume the duration time
Find truck name and sume the duration time

Time:09-21

Hi everybody I'm working on a productivity analisis by truck, and I want to get the truck name and sum the duration time. I get this error:

int() argument must be a string, a bytes-like object or a number, not 'Timedelta'

Here is my code

#Productivity analysis by truck

id = df['Vehicle ID']
vehicles = id.drop_duplicates()
vehicles = vehicles.reset_index().drop(['index'], axis=1)
N_Vehicles = len(vehicles)

df['Duration'] = pd.to_timedelta(df['Duration'].astype(str))

for i in range(N_Vehicles):

  X[i]= df[df['Vehicle ID'] == vehicles['Vehicle ID'][i]].Duration.sum()

X

Thank you in advance

CodePudding user response:

Try with this

for i,truck in enumerate(vehicles['Vehicle ID']):
    X[i]= df[df['Vehicle ID'] == truck].Duration.sum()

CodePudding user response:

the solution was to initialize the vector X as follows:

X = [None] * N_Vehicles
  • Related