To transform a date string in the format '30-06-2022' to '2022-06-30' using pd.to_datetime
in pandas, you can specify the format of the input date string using the format
parameter. Here's an example:
main.py254 chars13 lines
Output:
main.py11 chars2 lines
In the above code, pd.to_datetime
is used to convert the date string to a pandas datetime
object. The format
parameter is set to '%d-%m-%Y'
to match the format of the input date string.
Then, strftime
method is used to transform the date into the desired format '%Y-%m-%d'.
Note: Make sure to use the correct format codes in format
and strftime
to match the input and output date formats respectively.
gistlibby LogSnag