0

I'm doing some python code in Jupyter. When I import my spreadsheet using Pandas, the date column automatically appears in yyyy/mm/dd format and I would like it to be in dd/mm/yyyy (that is the brazilian standart) as it is in my original spreadsheet because when I insert that column into a variable , it comes with this information + 00:00:00.

As I'm creating for automation in sending messages via Whatsapp, I won't be able to change line by line before sending the message.

1 Answers1

1

Use pandas date/time function, such as pd.to_datetime to do the conversion for you and dt.strftime to format as text.

Here is an example:

# dummy data
df = pd.DataFrame({'date_before': ['2021/01/01', '2021/01/02', '2021/01/03', '2021/01/04',
       '2021/01/05']})
# conversion
df['date_after'] = pd.to_datetime(df['date_before']).dt.strftime('%d/%m/%Y')

output:

  date_before  date_after
0  2021-01-01  01/01/2021
1  2021-01-02  02/01/2021
2  2021-01-03  03/01/2021
3  2021-01-04  04/01/2021
4  2021-01-05  05/01/2021

NB. if you want to overwrite the column, just assign back to the same name

df['date'] = pd.to_datetime(df['date']).dt.strftime('%d/%m/%Y')
mozway
  • 194,879
  • 13
  • 39
  • 75