Home > front end >  How to change the Date column format pandas?
How to change the Date column format pandas?

Time:12-24

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 Python\Instagram\Postagem.xlsx")

print(df)

enter image description here

I need the date to be the same as the image below

enter image description here

CodePudding user response:

it's very confusing because you're using 2 different format 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)
  • Related