DEV Community

Nilotpal Choudhury
Nilotpal Choudhury

Posted on

Answer: Pandas delete all rows that are not a 'datetime' type

Use pd.to_datetime with parameter errors='coerce' to make non-dates into NaT null values. Then you can drop those rows

df['Date'] = pd.to_datetime(df['Date'], errors='coerce') df = df.dropna(subset=['Date']) df 

enter image description here

Top comments (0)