1

I'm working with big data in pandas and I have a problem with the format of the dates, this is the format of one column

Wed Feb 24 12:06:14 +0000 2021

and I think it is easier to change the format of all the columns with a format like this

'%d/%m/%Y, %H:%M:%S'

how can i do that?

1
  • 1
    pandas.to_datetime('Wed Feb 24 12:06:14 +0000 2021').strftime('%d/%m/%Y, %H:%M:%S') Commented Apr 14, 2021 at 3:30

2 Answers 2

2

Does this work for you?

pandas.to_datetime(s, format='%d/%m/%Y, %H:%M:%S')   

Source: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the following function for your dataset.

def change_format(x):
format = dt.datetime.strptime(x, "%a %b %d %H:%M:%S %z  %Y")
new_format = format.strftime('%d/%m/%Y, %H:%M:%S')
return new_format

Then apply it using df['date_column'] = df['date_column'].apply(change_format). Here df is your dataset.

1 Comment

I think this works but when I used it I have this problem... "time data 'nan' does not match format '%a %b %d %H:%M:%S %z %Y'" and its weird because i don´t have any row with NaN and the data is in format 'str'

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.