How can pandas set up filtering with an uncertain number of conditions and forms?

Viewed 21

I have a DataFrame that looks something like this.

    Column 1    Column 2    Column 3
0   ABC           1         Sunny
1   EFG           2         Rainy
2   HIJ           3         Cloudy
3   KLM           4         Thunder

I now want to use filtering with multiple conditions, and I know that if filtering with a given condition can be done with this statement.

df[df["Cloumn 1"] == "ABC" & other conditions]

But this is not flexible enough, my user may use only one condition this time or add another condition, and may want to use <= such a comparison character, if in the code to write dead conditions, then it is very inconvenient when encountering this method.

How can I write filtering code with uncertain number and format of conditions? (Like WHERE Cloumn_1 = 'ABC', Cloumn_2 = '2' in a SQL query statement)

0 Answers
Related