Manik Madhikermi
Manik Madhikermi

Reputation: 1

Error in python while converting string to datetime with timezone

Code:

pd.to_datetime(dataset['startdate'] ,format="%Y-%m-%d %H:%M:%S%Z")

I got following error

ValueError: time data '2020-02-25 14:56:05+01' does not match format '%Y-%m-%d %H:%M:%S%Z' (match)

help much appreciate.

Upvotes: 0

Views: 80

Answers (2)

Manik Madhikermi
Manik Madhikermi

Reputation: 1

Times series data contains +01 and +02 as well due to daylight saving. That was causing an error. Should be using %z as well

Upvotes: 0

Faboor
Faboor

Reputation: 1383

Your format has a %Z (uppercase) at the end, which according to docs timezone name (like GMT, PSD …). You probably want to use %z (lowercase) which is UTC offset (like ±HHMM[SS[.ffffff]]). However not sure if that would work +01, you might need +0100.

Upvotes: 1

Related Questions