0

I have a column having data of dates having date format - mm/dd/yyyy and i want to change its format to dd-mmm-yyyy. Can anyone help me regarding this.

Like any code which make 10/12/2018 to 12-Oct-2018.

Also I need that it will not lose its properties. Like when i export the data in excel then after applying filter on date column it will remain as come under 2018 in drop bar and not in 12-Oct-2018.

Like in excel when i apply filter the it needs to show-

2018 2017 etc

and not like

12-Oct-2018 10-Oct-2018 5-Sep-2017

user10498480
  • 1
  • 1
  • 2
  • 1
    Possible duplicate of [How to print date in a regular format in Python?](https://stackoverflow.com/questions/311627/how-to-print-date-in-a-regular-format-in-python) – Jan Oct 13 '18 at 09:25
  • Possible duplicate of [How to change the datetime format in pandas](https://stackoverflow.com/questions/38067704/how-to-change-the-datetime-format-in-pandas) – Abhi Oct 13 '18 at 09:27

1 Answers1

3

Use pandas.Series.dt.strftime function:

import pandas as pd

time = pd.DataFrame({'TimeColumns': {0: '10/13/2018'}}) #create time object - in your case get column values

time['TimeColumns'] = pd.to_datetime(time.TimeColumns)


time['ModifiedTimeColumns'] = time['TimeColumns'].dt.strftime('%d-%b-%Y') # change time formatting
print(time['ModifiedTimeColumns'])

Results:

0    13-Oct-2018
Name: ModifiedTimeColumns, dtype: object
kosist
  • 2,868
  • 2
  • 17
  • 30