0

I have a dataset which I attached a sample of it. My goal is to find the average time that it takes to finish each process. I use the following code:

import pandas as pd
df = pd.read_csv(....)
df['Start Time']=pd.to_datetime(df['Start Time'])
df['Finish Time']=pd.to_datetime(df['Finish Time'])
df['Process'] = df['Process'].astype("category")
df['Duration'] = df['Finish Time']-df['Start Time']
sectors = df.groupby('Process')
sectors['Duration'].mean()

However, whenever I run the code I get the following error:

No numeric types to aggregate

Any help would be appreciated.

File = https://filebin.net/0698p6q9or49ctw6/bb.csv?t=77zhetpd

PS: 1. Here is the result When I used dt.days:

A 0.5

B 0.0

C 0.0

But I am looking for sth like this:

Average A = 16.54305554 hours

Average B = 0.67 hours

Average C = 1.37 hours

shirin elahi
  • 105
  • 1
  • 9
  • 1
    Possible duplicate of [Pandas: Subtracting two date columns and the result being an integer](https://stackoverflow.com/questions/37840812/pandas-subtracting-two-date-columns-and-the-result-being-an-integer) – G. Anderson Sep 26 '19 at 16:09
  • How precise you want the mean to be? You probably want to convert datetime/timedelta to, say microseconds, and take the mean. – Quang Hoang Sep 26 '19 at 16:10
  • @G.Anderson unfortunately the result that I want is not like the one the other guy in that topic was looking for. – shirin elahi Sep 26 '19 at 17:33

1 Answers1

0

I use the following code and it worked:

df['Duration'] = (df['Duration']/np.timedelta64(1,'D'))*24
shirin elahi
  • 105
  • 1
  • 9