0

I have a column in a dataframe of type datetime64[ns]. I am trying to compare it to a date constant like below:

df_new=df_old[df_old['date_col'] > pd.to_datetime('2018-11-01')]

I get:

invalid type comparison

What did I do wrong?

BENY
  • 317,841
  • 20
  • 164
  • 234
Victor
  • 16,609
  • 71
  • 229
  • 409
  • 2
    Show us some sample data ? – BENY Jan 07 '19 at 20:56
  • 3
    Might be useful to get `df_new.dtypes` my spidey sense says `df_old['date_col']` isn't really a date. – Polkaguy6000 Jan 07 '19 at 21:32
  • 1
    as suggested your df column is probably not datetime: `df = pd.DataFrame(pd.date_range('2018-01-01', '2018-01-10'))` then do `df[df[0] > pd.to_datetime('2018-01-04')]` and it works as expected. – It_is_Chris Jan 08 '19 at 05:01

0 Answers0