what is the format of this date '01-11-2017' when converting with pd.to_datetime in python

To convert the date '01-11-2017' to datetime format using pd.to_datetime() in Python, you can specify the format of the input date using the format parameter. In this case, the format of the input date is 'dd-mm-yyyy'.

Here is an example of how to convert the date using pd.to_datetime():

main.py
import pandas as pd

date_str = '01-11-2017'
datetime_obj = pd.to_datetime(date_str, format='%d-%m-%Y')

print(datetime_obj)
125 chars
7 lines

The %d represents the day, %m represents the month, and %Y represents the four-digit year in the format. By specifying the format parameter as '%d-%m-%Y', the pd.to_datetime() function will correctly parse the date string and convert it to a datetime object.

Output:

main.py
2017-11-01 00:00:00
20 chars
2 lines

Now, datetime_obj contains the converted datetime object.

gistlibby LogSnag