How can I change the Date column format in pandas?

Question:

I need to convert the date to Day, Month and Year. I tried some alternatives, but I was unsuccessful.

import pandas as pd
df = pd.read_excel(r"C:__Imagens e Planilhas PythonInstagramPostagem.xlsx")

print(df)
Asked By: Felipe

||

Answers:

It’s very confusing, because you’re using two different formats between the image and the expected result (and you write you want the same).

Clarify that data is a date with:

df['data']= = pd.to_datetime(df['data'])

Once you have this, just change the format with:

my_format = '%m-%d-%Y'
df['data'] = df['data'].dt.strftime(my_format)
Answered By: pylos
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.