Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tz_convert in pandas does not work for any city in India

the below command seems to work for a other locations in Asia except for any location in India. Is there a bug here or am I missing something? this works:

pd.to_datetime(pd.datetime.now()).tz_localize('US/Pacific').tz_convert('Asia/Hong_Kong')
pd.to_datetime(pd.datetime.now()).tz_localize('US/Pacific').tz_convert('Asia/Karachi'
pd.to_datetime(pd.datetime.now()).tz_localize('US/Pacific').tz_convert('Asia/Dubai')

this does not work with exactly the same format (like any location in India):

pd.to_datetime(pd.datetime.now()).tz_localize('US/Pacific').tz_convert('Asia/New_Delhi')

throwing the below error

File "C:\Miniconda\lib\site-packages\pytz\__init__.py", line 180, in timezone
raise UnknownTimeZoneError(zone) UnknownTimeZoneError: 'Asia/New_Delhi'
like image 680
Siraj S. Avatar asked Feb 07 '23 19:02

Siraj S.


1 Answers

pandas uses the the time zones in the tz database. You can find a list of all available time zone codes for example in wikipedia.

For India, you would use Asia/Kolkata

pd.to_datetime(pd.datetime.now()).tz_localize('US/Pacific').tz_convert('Asia/Kolkata')
like image 124
cel Avatar answered Feb 10 '23 09:02

cel