Skip to content

ENH: Query function to have a star * for all columns #59140

@dstone42

Description

@dstone42

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I have a data frame that has a large number of columns that have positive numeric values except the last 4 columns. There are some rows with missing data, but in this dataset, they denote that by using a very large negative number. My plan was to use the query function to filter the rows to only those that have values greater than or equal to zero in every numeric column.

Feature Description

I wish the query function would let me do something like this df.query('* >= 0') the star * representing all columns. Better yet, would be if I could use star but subtract the columns to be excluded from that like df.query('* -state -county >= 0').

Alternative Solutions

What I am going to do is loop through the columns of the data frame and query on each one using a variable and exclude those non-numeric from my list. Like this:

column_list.remove('state')
column_list.remove('county')

for column in column_list:
    df = df.query('@column >= 0')

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds TriageIssue that has not been reviewed by a pandas team memberexpressionspd.eval, query

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions