Alex T
Alex T

Reputation: 3754

timedelta to float python

Hi I have this column in dataframe which is like this:

Days
96 days
96 days
47 days
91 days
64 days

I wanted to plot it on the scatter plot, however I got the error saying:

TypeError: Cannot cast scalar from dtype('float64') to dtype('<m8[ns]') according to the rule 'same_kind'

Im pretty sure the problem lays in that column above, so I need to change it from this timedelta type to some plotable type, but not sure how can I do it? Any ideas?

Upvotes: 1

Views: 2385

Answers (1)

elPastor
elPastor

Reputation: 8956

You just need to convert the Days column to integer format and plot as normal:

df['daysInt'] = df['Days'].apply(lambda x: x.days)

...will give you the int column, and you know the rest.

Upvotes: 3

Related Questions