Dataframe loc with parameter str

346 Views Asked by At

I have an interface which gets a str with the condition to be executed.

Is it possible to directly pass this str in my pandas loc?

example:

df:
{'col A': [1, 2, 3, 4],
'col B': ['a', 'b', 'c', 'd']}

entry_str = "col A == 2"

df = df.loc[entry_str]
1

There are 1 best solutions below

0
On

just use df.query('col A == 2')