0

I have code such as below:

df['time_local'] = pd.to_datetime(df['unix_time'], unit='s').dt.tz_localize('UTC').dt.tz_convert('Europe/Vienna')

This gives me timestamps such as:

Input:

    Unix_Time
    1507126654
    1507126654

Output with above code:

        Time_local
2017-10-15 13:05:39+02:00
2017-10-04 22:16:13+02:00

Output:

     Time_local
2017-10-15 13:05:39
2017-10-04 22:16:13

How can I remove the offset +02:00 and is this local time even though I have to use tz.localize('UTC') in my code to convert?

Chris90
  • 1,868
  • 5
  • 20
  • 42
  • Can you instead show 2 rows of input and expected output? It isn't clear what the expected behavior is. – cs95 Dec 14 '19 at 22:14
  • Thanks, try `tz_localize`: `df['Date'].dt.tz_localize(None)` – cs95 Dec 14 '19 at 22:19
  • that doesnt work as that only works on index – Chris90 Dec 14 '19 at 22:19
  • "as that only works on index" no, it works on any datetime series or DatetimeIndex. Just assign it back, it seems to do exactly what you want on my machine, so I don't see why it shouldn't work for you. – cs95 Dec 14 '19 at 22:20
  • You closed the question but that post doesnt answer this it wont let me set to a specific local timezone such as europe/germany – Chris90 Dec 14 '19 at 22:20
  • You want to display the column without any timezone info but don't want to lose the timezone info on the column? Is this only for the sake of printing? You can try `df['Date_str'] = df['Date'].dt.tz_localize(None).astype(str)` but you can't solve this for the original Date column. – cs95 Dec 14 '19 at 22:24

0 Answers0