To change the format of a date in a pandas DataFrame, you can use the to_datetime
function from the pandas library along with the strftime
function from the datetime library to format the date as desired.
Here's an example of how you can change the format of a date column in a pandas DataFrame from "2023-04-10" to "01-jan-2015":
main.py383 chars15 lines
Output:
main.py59 chars5 lines
In this example, we first convert the 'date' column to datetime format using pd.to_datetime()
. Then, we use dt.strftime()
to change the format of the date to '%d-%b-%Y', where '%d' represents the day, '%b' represents the abbreviated month name, and '%Y' represents the year in 4 digits.
gistlibby LogSnag