I am trying to parse data from 2018-03-31 15:58
to 2018-03-31T15:58:00Z
. Is it possible to achieve this using dataframe or another library?
Asked
Active
Viewed 36 times
0
-
Possible duplicate of [Parse date string and change format](https://stackoverflow.com/questions/2265357/parse-date-string-and-change-format) – Georgy Mar 31 '18 at 19:21
1 Answers
2
Using datetime
module
import datetime
s = "2018-03-31 15:58"
print(datetime.datetime.strptime(s , "%Y-%m-%d %H:%M").strftime("%Y-%m-%dT%H:%M:%SZ"))
Output:
2018-03-31T15:58:00Z
Or using pandas
import pandas as pd
s = "2018-03-31 15:58"
print(pd.to_datetime(s).strftime("%Y-%m-%dT%H:%M:%SZ"))

Rakesh
- 81,458
- 17
- 76
- 113