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

后端 未结 1 1049
不知归路
不知归路 2021-02-04 09:11

I\'ve got a large file with login information for a list of users. The problem is that the file includes other information in the Date column. I would like to remov

相关标签:
1条回答
  • 2021-02-04 09:32

    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
    

    0 讨论(0)
提交回复
热议问题