Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 3 tasks
dstone42 opened this issue Jun 28, 2024 · 1 comment
Open
1 of 3 tasks

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

dstone42 opened this issue Jun 28, 2024 · 1 comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@dstone42
Copy link

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

@dstone42 dstone42 added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 28, 2024
@Delengowski
Copy link
Contributor

Delengowski commented Jul 15, 2024

Do you have an idea how this would be implemented with the ast parser used to parse the query string? What if there's a column named *? Can it even parse it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants