I have a date column in my DataFrame say df_dob
and it looks like -
id | DOB |
---|---|
23312 | 31-12-9999 |
1482 | 31-12-9999 |
807 | #VALUE! |
2201 | 06-12-1925 |
653 | 01/01/1855 |
108 | 01/01/1855 |
768 | 1967-02-20 |
What I want to print is a list of unique years like - `['9999', '1925', '1855', '1967']
basically through this list I just wanted to check whether there is some unwanted year is present or not.
I have tried(pasted my code below) but getting ValueError: time data 01/01/1855 doesn't match format specified
and could not resolve it.
df_dob['DOB'] = df_dob['DOB'].replace('01/01/1855 00:00:00', '1855-01-01')
df_dob['DOB'] = pd.to_datetime(df_dob.DOB, format='%Y-%m-%d')
df_dob['DOB'] = df_dob['DOB'].dt.strftime('%Y-%m-%d')
print(np.unique(df_dob['DOB']))
# print(list(df_dob['DOB'].year.unique()))
P.S - when I print df_dob['DOB']
, I get values like - 1967-02-20 00:00:00