mans
mans

Reputation: 18168

Error from python panda timedelta function

I have this line of code:

df['datetime']= pd.to_datetime(df['date'])+ pd.to_timedelta(df['hour']/100,unit='hour')

and I am getting this error:

invalid timedelta unit hour provided

the strange things are that it works on another PC but not in this PC.

Upvotes: 0

Views: 54

Answers (1)

Deepstop
Deepstop

Reputation: 3807

OK I'll take a stab at it. Pandas appears to have introduced unit=hour and unit=hours in either V0.24 or 0.25. If running an earlier version, then use

df['datetime']= pd.to_datetime(df['date'])+ pd.to_timedelta(df['hour']/100,unit='h')

instead. The docs from 0.23.4 don't show hour and hours as options, while the docs for 0.25 clearly do. That would explain the different behaviour on different machines.

Upvotes: 1

Related Questions