-1

I have a column such as

  time
1508089361
1508065388
1508011482

I want to convert this to a local timestamp setting the timezone for a particular region, so I use the code below:

df['time'] = pd.to_datetime(df['time'], unit='s').dt.tz_localize('UTC').dt.tz_convert('Europe/Berlin')

It returns me a column with values as below:

          time
2017-10-04 16:17:34+02:00   
2017-10-04 14:17:34+02:00   
2017-10-04 08:17:34+02:00   

IS there any way can I remove the +02:00 so I can just have a normal timestamp? the column type is a datetime64[ns, Europe/Berlin]

I want to join two dfs on these times but cannot since the other df has these times already in normal datetime timestamp format such as:

       Time
2017-10-09 00:00:00
2017-10-09 00:00:00
2017-10-09 00:00:00
2017-10-09 00:00:00

Thanks!

Chris90
  • 1,868
  • 5
  • 20
  • 42
  • Stop at the UTC? – thebjorn Dec 15 '19 at 01:17
  • But I need it in local time of that region or city @thebjorn – Chris90 Dec 15 '19 at 01:19
  • "Normal datetime timestamp format" would be UTC (you'll likely save yourself lots of headaches if you convert everything to UTC first). If you absolutely want localtime, then this might help: https://stackoverflow.com/questions/4770297/convert-utc-datetime-string-to-local-datetime – thebjorn Dec 15 '19 at 01:27

1 Answers1

1

Yes you can. Please use this function

dt.strftime('%Y-%m-%d %H:%M:%S')

More details on formatting https://strftime.org/

Alexandr Shurigin
  • 3,921
  • 1
  • 13
  • 25