I have a df with a column 'start date'. It has date values. They are of string type. The column also has blank values.
--> df.loc[0,'start date']
output : '2022-10-04'
--> type(df.loc[0,'start date'])
output : str
I have imported datetime
import datetime
And I try to convert this entire column to pandas datetime type.
df['start date'] = pd.to_datetime(df['start date'], errors='coerce')
Because this will give time stamp as well, I want to keep only the date, I did this:
df['start date'] = pd.to_datetime(df['start date'], errors='coerce').datetime.date
But this gives an Attribute error :AttributeError: 'Series' object has no attribute 'datetime' Whereas if I tweak the code to :
df['start date'] = pd.to_datetime(df['start date'], errors='coerce').dt.date
It works!
What's happening?! Any help in understanding the concept behind this would be appreciated :)