Home > Mobile >  Invalid comparison error when converting datatime data type
Invalid comparison error when converting datatime data type

Time:09-25

Getting the error "Invalid comparison between dtype=datetime64[ns] and date"

import pandas as pd
from datetime import date

df[['starttime']

2019-06-29 12:00:20 AM

df['starttime_datetime'] = pd.to_datetime(df['starttime'])

df['starttime_datetime']

2019-06-29 00:00:20

df = df[df['starttime_datetime']<date(2019, 6, 30)]

"Invalid comparison between dtype=datetime64[ns] and date"

CodePudding user response:

Pandas datetime comparison can't be used with the datetime module.

I suggest you to just use string comparison:

df = df[df['starttime_datetime'] < '2019-06-30']
  • Related