0
$\begingroup$

I have measurements of pollutants. data = data.set_index(data.index.tz_localize(timezone('EET'), ambiguous='NaT', nonexistent='NaT').tz_convert('UTC')) This command converts the EET time to UTC. It considers, 2 hours difference in winter and 3 in summer.

But I would like 2 hours difference all year, for both winter and summer.

Thanks, Dimitris

$\endgroup$

2 Answers 2

1
$\begingroup$

It might be better to localize the data into GMT+2 or GMT+3 instead of EET. EET is GMT+2 in the winter, and GMT+3 in the summer.

Pandas infers this and applies these timezones to the dataset, which is why it goes from +2 to +3 difference in winter/summer.

Try replacing 'EET' with 'Etc/GMT+2'.

data.set_index(data.index.tz_localize(timezone('Etc/GMT+2'), ambiguous='NaT', nonexistent='NaT').tz_convert('UTC'))
$\endgroup$
4
  • $\begingroup$ hi, I have upvoted your answer, many thanks. I haven't accepted it due to + and - described in my answer. $\endgroup$ Apr 17 at 9:06
  • 1
    $\begingroup$ Thanks, I'm glad you found a solution! $\endgroup$
    – Rowan Nag
    Apr 17 at 15:14
  • $\begingroup$ Wouldn't data = data.set_index(data.index.tz_localize(timezone('EEST'), ambiguous='NaT', nonexistent='NaT').tz_convert('UTC')) just work? I see it's name is in the timezone name set for Egypt in python.readthedocs.io/en/latest/library/time.html $\endgroup$ Apr 18 at 6:47
  • $\begingroup$ @JeopardyTempest hello, no : 1) eest in 3 hours ahead i want 2. 2) it returns error. Traceback (most recent call last): File "H:\My Drive\PhD\2024\climpact\rest_of_greece.py", line 293, in <module> dict_2019_data[str(file)] = dict_2019_data[str(file)].set_index(dict_2019_data[str(file)].index.tz_localize(timezone('EEST'), ambiguous='NaT', nonexistent='NaT') File "C:\Users\Administrator\anaconda3_synced\lib\site-packages\pytz_init_.py", line 181, in timezone raise UnknownTimeZoneError(zone) UnknownTimeZoneError: 'EEST' $\endgroup$ Apr 18 at 10:38
0
$\begingroup$

The answer of Rowan was very helpful. But, it needs Etc/GMT-2 instead of Etc/GMT+2 to make the conversion. so,

data.set_index(data.index.tz_localize(timezone('Etc/GMT-2'), ambiguous='NaT', nonexistent='NaT').tz_convert('UTC'))

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.