To convert a date represented as "01-jan-2015" into a desired format using pandas in Python, you can use the to_datetime()
function along with strftime()
.
Here's an example of how you can achieve this:
main.py413 chars14 lines
Output:
main.py56 chars5 lines
In the above code, pd.to_datetime()
is used to convert the 'date' column to a pandas datetime object, by specifying the original date format as '%d-%b-%Y'
. Then dt.strftime()
is used to convert the datetime object to the desired format specified as '%Y-%m-%d'
.
gistlibby LogSnag