df_filtered = df.query('a > 0 and 0 < b < 2')
#If you need to refer to python variables in your query, the documentation says, "You can refer to variables in the environment by prefixing them with an ‘@’ character like @a + b". Note that the following are valid: df.query('a in list([1,2])'), s = set([1,2]); df.query('a in @s'). –
#teichert
df.query('D > B').query('C > B')
# equivalent to
# df.query('D > B and C > B')
# but defeats the purpose of demonstrating chaining
A B C D E
0 0 2 7 3 8
1 7 0 6 8 6
4 3 6 7 7 4
5 5 3 7 5 9
7 6 2 6 6 5
df_filtered = df.query('a > 0 and 0 < b < 2')
#If you need to refer to python variables in your query, the documentation says, "You can refer to variables in the environment by prefixing them with an ‘@’ character like @a + b". Note that the following are valid: df.query('a in list([1,2])'), s = set([1,2]); df.query('a in @s'). –
#teichert
df.query('D > B').query('C > B')
# equivalent to
# df.query('D > B and C > B')
# but defeats the purpose of demonstrating chaining
A B C D E
0 0 2 7 3 8
1 7 0 6 8 6
4 3 6 7 7 4
5 5 3 7 5 9
7 6 2 6 6 5