Is it possible to export pandas DataFrame to Excel to remove tzinfo?

I have a timeline that states TimeSeries in pandas 0.10.1. I want to export to Excel, but the time zone prevents recognizing dates as dates in Excel.

In [40]: resultado Out[40]: fecha_hora 2013-04-11 13:00:00+02:00 31475.568 2013-04-11 14:00:00+02:00 37263.072 2013-04-11 15:00:00+02:00 35979.434 2013-04-11 16:00:00+02:00 35132.890 2013-04-11 17:00:00+02:00 36356.584 

If I split tzinfo into .tz_convert(None) , the date is converted to UTC:

 In [41]: resultado.tz_convert(None) Out[41]: fecha_hora 2013-04-11 11:00:00 31475.568 2013-04-11 12:00:00 37263.072 2013-04-11 13:00:00 35979.434 2013-04-11 14:00:00 35132.890 2013-04-11 15:00:00 36356.584 

Is there a TimeSeries method to apply .replace(tzinfo=None) to each date in the index?

Alternatively, is there a way to correctly export TimeSeries to Excel?

0
source share
1 answer

You can simply create a copy without a time zone.

 import pandas as pa time = pa.Timestamp('2013-04-16 10:08', tz='Europe/Berlin') time_wo_tz = pa.datetime(year=time.year, month=time.month, day=time.day, hour=time.hour, minute=time.minute, second=time.second, microsecond=time.microsecond) 

If you want to convert the entire time series index, use list comprehension.

 ts.index = [pa.datetime(year=x.year, month=x.month, day=x.day, hour=x.hour, minute=x.minute, second=x.second, microsecond=x.microsecond) for x in ts.index] 
+2
source

Source: https://habr.com/ru/post/1239406/


All Articles