Assume we have the following dataframe:
d = {'col1': ['a1', 'b1', 'c1', 'a1'], 'col2': ['a2', 'b2', 'b2', 'c2'], 'year':[2011, 2011, 2012, 2012], 'rank':[1, 2, 1, 2]}
df = pd.DataFrame(data=d).set_index(['year', 'rank']).sort_index()
col1 col2
year rank
2011 1 a1 a2
2 b1 b2
2012 1 c1 b2
2 a1 c2
How can I select all columns where col1 != 'a1' or year != 2011?
If year wouldn't be an index, I could do this by
df[(df.col1 != 'a1') | (df.year != 2011)]
However, as year is an index, df.year would throw an AttributeError.
How can I formulate the condition for the index? Thanks in advance!