How to convert list of timestamp columns in Python Pandas with Time zone offset
I have list of four columns in a Pandas Data frame which has Timestamp with Time zone offset as follows: ts_lst = [SLA_START_TIME, SLA_STOP_TIME, RES_START_TIME, RES_STOP_TIME] Sample value: 2017-06-27T09:30:19.757-0400
For each of the columns in the ts_lst what is the optimal solution to
This should work:
for column in [x for x in df.columns[df.columns.str.contains("time", case=False)]]:
df[column] = (
pd.to_datetime(df[column], utc=True)
.dt.tz_convert("America/New_York")
.dt.tz_localize(None)
.dt.floor("S")
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.