简体   繁体   中英

Converting two date formats to one in a dataframe column in Python

I have a excel sheet, which i am reading using Python. There's a date column, where the data is in below format:

2017/10/02 13:51:39 BST
2017/11/08 19:55:11 GMT

I need to convert the data to GMT format itself. Any ways to do so?

I think you need replace by dict with to_datetime :

df = pd.DataFrame({'date': ['2017/10/02 13:51:39 BST', '2017/11/08 19:55:11 GMT']})


d = {'BST':'+0100', 'GMT':'+0000'}
df['date'] = pd.to_datetime(df['date'].replace(d, regex=True))
print (df)

                 date
0 2017-10-02 12:51:39
1 2017-11-08 19:55:11

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM