I have a dataframe df with a date column of strings like this one :
Date
01/06/2022
03/07/2022
18/05/2022
12/02/2021
WK28
WK30
15/09/2021
09/02/2021
...
I want to update my dataframe with the last 6 months data AND the wrong format data (WK28, WK30...) like this :
Date
01/06/2022
03/07/2022
18/05/2022
WK28
WK30
...
I managed to keep the last 6 months dates by converting the column to Date format and computing a mask with a condition :
df['Dates']=pd.to_datetime(df['Dates'], errors='coerce', dayfirst=True)
mask = df['Dates'] >= pd.Timestamp((datetime.today() - timedelta(days=180)).date())
df = df[mask]
But how can I also keep the wrong format data ?