Skip to content

Need syntax sugar for dataframe row selection #2035

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

Closed
halleygithub opened this issue Oct 7, 2012 · 4 comments
Closed

Need syntax sugar for dataframe row selection #2035

halleygithub opened this issue Oct 7, 2012 · 4 comments
Milestone

Comments

@halleygithub
Copy link

Current dataframe row selection by columns is wordy , 'rowsl()' method is need to make it looks simple.

def _rowsl(df, selection_str):
#syntax sugar to simplify column selection:

df.rowsl('col_1>0.5 & col_2<40') act as

df[(df['col_1']>0.5) & (df['col_2']<40)]

#not_implement_yet
#rst = parsing_and_ filtering
return rst

DataFrame.rowsl = _rowsl

@changhiskhan
Copy link
Contributor

Note you can simplify the syntax by using attribute column access: df[(df.col_1 > 0.5) & (df.col_2 < 40)]

@halleygithub
Copy link
Author

accept, but df['col_1 > 0.5 & col_2 < 40'] might looks simple

@dsm054
Copy link
Contributor

dsm054 commented Dec 16, 2013

I think the currently-pending query syntax addresses this issue:

>>> df = pd.DataFrame({"col_1": [0.1, 0.2, 0.7, 0.8], "col_2": [10, 50, 20, 60]})
>>> df
   col_1  col_2
0    0.1     10
1    0.2     50
2    0.7     20
3    0.8     60

[4 rows x 2 columns]
>>> df.query("col_1 > 0.5 & col_2 < 40")
   col_1  col_2
2    0.7     20

[1 rows x 2 columns]

@jreback
Copy link
Contributor

jreback commented Dec 16, 2013

closed by #4164

@jreback jreback closed this as completed Dec 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants