1

I am trying to change the date format reported in the header. where the date formats reported are as the below 1-2-22 thru 1-8-22, 1-16-22 thru 1-22-22 need to update the date formats to dd-mm-yyyy in the header

Sin
  • 11
  • 1
  • 1
    Hope u find your answer in the duplicate of https://stackoverflow.com/questions/38067704/how-to-change-the-datetime-format-in-pandas – joshii_h Feb 03 '22 at 09:23
  • 1
    Does this answer your question? [How to change the datetime format in Pandas](https://stackoverflow.com/questions/38067704/how-to-change-the-datetime-format-in-pandas) – joshii_h Feb 03 '22 at 09:25

2 Answers2

2
df['Date'].dt.strftime('%d/%m/%Y')
tomerar
  • 805
  • 5
  • 10
0
import pandas as pd

list_of_dates = ['2018-10-26 12:00', '2018-10-26 12:00', '2018-10-26 12:00']

dates_df = pd.DataFrame(list_of_dates, columns=['date'])

dates_df['date'] = pd.to_datetime(dates_df['date'])


dates_df['date']= dates_df['date'].dt.strftime('%m/%d/%Y')

print(dates_df)
#          date
# 0  10/26/2018
# 1  10/26/2018
# 2  10/26/2018
evanstjabadi
  • 305
  • 3
  • 10