0

I have a Pandas series time of dates and times, like:

UTC:  
 0   2015-01-01 00:00:00
1   2015-01-01 01:00:00
2   2015-01-01 02:00:00
3   2015-01-01 03:00:00
4   2015-01-01 04:00:00
Name: DT, dtype: datetime64[ns] 

That I'd like to convert to another timezone:

time2 = time.dt.tz_localize('UTC').dt.tz_convert('Europe/Rome')
print("CET: ",'\n', time2)

CET:  
0   2015-01-01 01:00:00+01:00
1   2015-01-01 02:00:00+01:00
2   2015-01-01 03:00:00+01:00
3   2015-01-01 04:00:00+01:00
4   2015-01-01 05:00:00+01:00
Name: DT, dtype: datetime64[ns, Europe/Rome]

But, the result is not what I need. I want it in the form 2015-01-01 02:00:00 (the local time at UTC 01:00:00), not 2015-01-01 01:00:00+01:00.

How can I do that?

EDIT: While there is another question that deal with this issue (Convert pandas timezone-aware DateTimeIndex to naive timestamp, but in certain timezone), I think this question is more to the point, providing a clear and concise example for what appears a common problem.

Fabio Capezzuoli
  • 599
  • 7
  • 23
  • 1
    Try this maybe? https://stackoverflow.com/questions/16628819/convert-pandas-timezone-aware-datetimeindex-to-naive-timestamp-but-in-certain-t – run-out Feb 07 '19 at 09:47
  • 1
    Yes, that's what I needed. – Fabio Capezzuoli Feb 07 '19 at 10:11
  • Possible duplicate of [Convert pandas timezone-aware DateTimeIndex to naive timestamp, but in certain timezone](https://stackoverflow.com/questions/16628819/convert-pandas-timezone-aware-datetimeindex-to-naive-timestamp-but-in-certain-t) – Brad Solomon Feb 07 '19 at 10:21

1 Answers1

1

I turns out that my question already has an answer here: Convert pandas timezone-aware DateTimeIndex to naive timestamp, but in certain timezone)

I just wasn't able to phrase my question correctly. Anyway, what works is:

time3 = time2.dt.tz_localize(None)
print("Naive: ",'\n', time3)

Naive:  
 0   2015-01-01 01:00:00
1   2015-01-01 02:00:00
2   2015-01-01 03:00:00
3   2015-01-01 04:00:00
4   2015-01-01 05:00:00
Name: DT, dtype: datetime64[ns]`
Fabio Capezzuoli
  • 599
  • 7
  • 23