Need help to understand pandas.to_datetime()

I am not able to understand the working of pandas.to_datetime() function.
I will be grateful if someone helps me to understand it.
Thanks in advance.

Screen Link:

My Code:
unrate['DATE'] = pd.to_datetime(unrate['DATE'])

What I know:
The function converts a date in text form (mm/dd/yyyy) to the datetime form (yyyy-mm-dd)

Screen Link:

My Code:
plt.plot(first_twelve['DATE'], first_twelve['VALUE'])

What I want to understand:
How does the date in form yyyy-mm-dd (e.g. 1948-01-01) plots on x axis labels without the day (e.g. Jan 1948) and how does the month number (e.g. 01) converts to name (e.g. Jan)

Hi Arti. I think your question is related to this one: Datetime object in line graph. The short answer to your question is that there’s stuff happening behind the scences in the way matplotlib presents dates on the graph. These are settings that can be tweaked, so I am guessing that Dataquest has them set up to show the date that way.

This article on Geeks for Geeks has a lot of info, but I thought this sentence was especially helpful:

Date and datetime are an object in Python, so when you manipulate them, you are actually manipulating objects and not string or timestamps.

I hope any of that was helpful.

1 Like

Thank you for giving the link to the same post in the community.
At first, I felt like I am missing some concept of pandas but even after going through that course again, I couldn’t understand it.
I searched for it in community posts before posting but didn’t come across this one and made a post for getting help with it.
Thanks again for the help. :slightly_smiling_face:

No problem! It’s a lot to go through. I was only able to find it because your post triggered my memory. :smiley:

1 Like