0

new to pandas and I think I'm missing something really basic about dataframes.

e=pd.DataFrame(data={'a':[1,1,2,2,3,3],'b':[7,8,9,10,11,12],'c':[20,21,22,23,24,25]}).set_index(['a','c'])

how would I filter this dataframe based on the index a being greater than 2?

e.query('"a" > 2')

gives me

'>' not supported between instances of 'list' and 'int'
Dominik
  • 782
  • 7
  • 27
  • If you get rid of the index setting you could just do: `e[e['a'] > 2]` – smj Jan 17 '19 at 00:35
  • Try e[e.index.get_level_values(0) > 2] or e.query('a > 2') – Vaishali Jan 17 '19 at 00:36
  • The other question doesn't address using a boolean, which is where I was getting tripped up. most answers on SO use a list of values to filter the index. – Dominik Jan 17 '19 at 00:42
  • 1
    This is what I needed: `e.query('a > 2')` I've been working on this too long and didn't spot the ". i actually had just figured that out myself, but time to go home i think – Dominik Jan 17 '19 at 00:43

0 Answers0