1 I have a CSV containing a column data["timestamps1"] of GMT-timezone strings in this format:
2020-02-28T12:53:47.167Z
2 I want to get a new column with strings of the timezone in another tz-time which is Europe/Berlin, the format doesn't matter that much, e.g.
2020-02-28 13:53:47
How can i do that? I tried already parsing dates
import pandas as pd
from datetime import datetime
from pytz import timezone
path = "timestamps.csv"
data = pd.read_csv(path, sep=";", parse_dates= ["timestamps1"])
data['timestamps1_new'] = data['timestamps1'].dt.tz_localize('GMT').dt.tz_convert('Europe/Berlin')
Then i get the error "Already tz-aware, use tz_convert to convert." When I do not parse dates, i get "Can only use .dt accessor with datetimelike values". Even when I manipulate the string in this way, the error occurs:
data["timestamps1"] = data["timestamps1"].str[:-5]
data["timestamps1"] = data.timestamps1.replace("T"," ",regex=True)
Here are some example data:
data = {'timestamps': ['2020-11-28T13:14:57.463Z','2020-11-28T13:14:57.603Z','2020-11-28T13:14:57.618Z']}
data = pd.DataFrame(data=data)
Thanks a lot!
2020-02-28T12:53:47.167Z(ISO8601) automatically gets parsed to aware datetime (tzinfo set, UTC). so you simply need to convert:data['timestamps1_new'] = data['timestamps1'].dt.tz_convert('Europe/Berlin')