0

I have a pandas dataframe and I am trying to pull the rows that are greater than a date and less than another date. If I run the greater and less than dates separately, it works. If I use the & and try to do both at the same time, I get an error. Any ideas?

Error I am getting is:

TypeError: unsupported operand type(s) for &: 'float' and 'int'

This Works:

df_subset = (df.loc[(df['dump_date'].dt.date >= start)])

This Does Not Work

df_subset = (df.loc[(df['dump_date'].dt.date >= start)]) & (df.loc[(df['dump_date'].dt.date <= end)])
George M
  • 23
  • 7
  • 3
    Use a **single** `loc`: `df_subset = df.loc[(df['dump_date'].dt.date >= start) & (df['dump_date'].dt.date <= end)]`, or maybe better: `df_subset = df.loc[df['dump_date'].dt.date.between(start, end, inclusive='both')]` – mozway Oct 25 '22 at 14:25
  • Thanks, I got it. I took out the df.loc from each statement and it pulled in correctly. Thank you. – George M Oct 25 '22 at 14:43

0 Answers0