0

In my python function I get a dataframe and a condition as a string.

def my_def(df, condition):

The goal is to filter the dataframe by the condition, with pandas.

I've seen solutions like this one:

Select rows from a DataFrame based on values in a column in pandas

But it doesn't help me, because the condition parameter looks like this:

'name = 'you''

The filter is on the column "name" with value "you",

But in the solution above I must split the column name and the value from that string.

Is there a way to filter on all dataframes and not on a specific column?

In the end, It's like doing:

"where name = 'you'" 

on the dataframe, so I guess it is possible.

Thanks.

Błażej Michalik
  • 4,474
  • 40
  • 55
user2671057
  • 1,411
  • 2
  • 25
  • 43
  • 2
    Would `df.query("name == 'you'")` solve your problem? Or is it an issue that you have only one `=` (equal sign)? – MaxU - stand with Ukraine Aug 08 '17 at 12:13
  • Thanks for your help! the query function great. with "==" but that's ok. Is there a way to do same whit condition of null ? (is null or is not null). Because the check of nulls in column in pandas is different from the simple condition "name is null".. – user2671057 Aug 08 '17 at 14:28

0 Answers0