To change the format of a pandas datetime column from "30-nov-2023" to "30-11-2023" in Python, you can use the to_datetime
function from pandas along with the dt
accessor to format the datetime values.
Here is an example:
main.py368 chars14 lines
This will give the output:
main.py56 chars5 lines
In the above code, we first convert the 'date' column to datetime format using pd.to_datetime()
. Then, we use the dt.strftime()
method to change the date format to '%d-%m-%Y' (day-month-year). Finally, we assign the updated date column back to the DataFrame.
gistlibby LogSnag