I am new to python. I have a dataset I converted it to dataframe. all my dates are objects now. I need to convert them into dates in order to find the age of patients. My dimensions are 3400×14 long. there are date values inside which have incorrect syntax. I cannot find them. is there a way to find them?
JavaScript
x
2
1
Cdf['Birthday'] = Cdf['Birthday'].astype('datetime64[ns]')
2
I am using this formula to convert. I need date without time. I am getting an error which is “DateParseError: Invalid date specified (25/15)”
Thank you for help in advance
Advertisement
Answer
You can use pd.to_datetime
JavaScript
1
2
1
Cdf['date'] = pd.to_datetime(Cdf['Birthday'], errors='coerce')
2
and check for which values in this column have NaT
s as values. All invalid dates will be converted to NaT
. You can use
JavaScript
1
2
1
Cdf.loc[Cdf['date'].isnull(), 'date']
2
to find all values which are invalid.