Sometimes, we want to keep only date part when using Python pandas.to_datetime.
In this article, we’ll look at how to keep only date part when using Python pandas.to_datetime.
How to keep only date part when using Python pandas.to_datetime?
To keep only date part when using Python pandas.to_datetime, we can use the dt.date method.
For instance, we write
df['just_date'] = df['dates'].dt.date
to convert the values in the dates columns to dates and put them into the just_date column.
We can also keep the dates values as the datetime64 data type with normalize:
df['normalised_date'] = df['dates'].dt.normalize()
Conclusion
To keep only date part when using Python pandas.to_datetime, we can use the dt.date method.