Issue
I have a module to test whether user enter wrong birthday like
df1
0 19730505
1 19731027
2 19970230
3 NaN
We can clearly see 2 is wrong because there are no 30th day in February
If I use this statement, it would raise a value error
pd.to_datetime(df1,format="%Y%m%d")
ValueError: day is out of range for month
but I want to output the wrong conversion cell into False
My desired output is
0 True
1 True
2 False
3 False
Which module of datetime can I use here?
Solution
Check with
pd.to_datetime(df1,format="%Y%m%d",errors='coerce').notna()
Answered By - BENY
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.