I have DataFrame like that:
df = pd.DataFrame([
{
'name': 'Alexandra',
'surname': 'Johnson',
'age': 5
},
{
'name': 'Roland',
'surname': 'Hawking',
'age': 3
}
])
To find rows matching a certain condition I use combination of conditions:
df[((df['name']=='Roland') | (df['surname']=='Johnson')) & (df['age'] > 4)]
returning
name surname age
0 Alexandra Johnson 5
However, this does not scale well for several hundred thousand rows. To speed up search over a column I used to index that column:
indexed = df.set_index('name')
indexed[indexed.index == 'Roland']
For multiple columns I can use MultiIndex, however I don't know how can I use combination of boolean conditions with multiple indexes. Can you advice?