pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
42.57k stars 17.56k forks source link

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

Open dstone42 opened 2 days ago

dstone42 commented 2 days ago

Feature Type

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