1

I am having dataframe like

Input

Date
2020-12-21
2019-09-30
2019-12-04

I want to convert this specific date time format.

Expected Format

       Date
    2020-12-21T00:00:00Z
    2019-09-30T00:00:00Z
    2019-12-04T00:00:00Z

My current code

df.loc[:,'Date'] = pd.to_datetime(df.loc[:,'Date'])

Its not working correctly. How can this be fixed.

4
  • Could you elaborate on "Its not working correctly". Do you get an error or an unexpected result? Commented Feb 21, 2020 at 4:04
  • @PeptideWitch, I am not getting timestamp in this way T00:00:00Z Commented Feb 21, 2020 at 4:06
  • @PeptideWitch, I want to get the timestamp in this format T00:00:00Z Commented Feb 21, 2020 at 4:07
  • Do you need the datetime properties or the string format? Given your format just add 'T00:00:00Z' to the strings if the later. Commented Feb 21, 2020 at 4:37

1 Answer 1

2

I'm not sure there's a shortcut for ISO time format. Here's a hack around:

pd.to_datetime(df['Date']).dt.strftime("%Y-%m-%dT%H:%M:%SZ")

Output:

0    2020-12-21T00:00:00Z
1    2019-09-30T00:00:00Z
2    2019-12-04T00:00:00Z
Name: Date, dtype: object
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.