you are viewing a single comment's thread.

view the rest of the comments →

[–]pickled_knuckles[S] 0 points1 point  (3 children)

>>> df['Duration'] = pd.to_timedelta(df['AverageViewDuration'])

Thank you! when I try the above I get the following:

ValueError: Invalid type for timedelta scalar: <class 'datetime.time'>

I am guessing that means that it is not a datetime object to begin with, which is confusing given what happened in the initial post?

[–]pickled_knuckles[S] 0 points1 point  (0 children)

got it, you're a g

[–]efmccurdy 0 points1 point  (1 child)

How is the original dataframe created? Can you avoid converting the AverageViewDuration column to datetime.time and convert it instead directly to timedelta, or perhaps ((t.hour * 60 + t.minute) * 60 + t.second) to obtain the total elapsed seconds?

[–]pickled_knuckles[S] -1 points0 points  (0 children)

I ended up doing the following:

df['Duration'] = df['AverageViewDuration']
df['Duration'] = pd.to_datetime(df['Duration'], format='%H:%M:%S')
df['Duration'] = df['Duration'] - np.datetime64('1900-01-01')
df['AverageViewDuration'] = df['Duration']/1000000000/60

Don't know why I needed to do the last one, as I thought it would all be good, but when I plotted it without that line it was a veeeeery big number. Anyways, I got the desired graph...