Skip to content

Query on Series #12226

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
max-sixty opened this issue Feb 3, 2016 · 3 comments
Closed

Query on Series #12226

max-sixty opened this issue Feb 3, 2016 · 3 comments
Labels
API Design Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@max-sixty
Copy link
Contributor

I often find myself building a chain of logic, and then wanting to slice over some expression. Here's a contrived example:

In [12]: pd.Series(range(10)).mul(5).pipe(lambda x: x**2).pipe(lambda x: x-500)
Out[12]: 
0    -500
1    -475
2    -400
3    -275
4    -100
5     125
6     400
7     725
8    1100
9    1525
dtype: int64

...and then having to assign to a separate variable and slice using that. Which is not the worst affliction that could strike western civilization, but can disrupt the flow in a repl a little.

In [13]: s=pd.Series(range(10)).mul(5).pipe(lambda x: x**2).pipe(lambda x: x-500)

In [14]: s[s>200]
Out[14]: 
6     400
7     725
8    1100
9    1525
dtype: int64

Instead, would it be reasonable to extend query or filter to do this. For example:

pd.Series(range(10)).mul(5).pipe(lambda x: x**2).pipe(lambda x: x-500).query('>200')
or
pd.Series(range(10)).mul(5).pipe(lambda x: x**2).pipe(lambda x: x-500).filter(lambda x: x>200)

@jreback
Copy link
Contributor

jreback commented Feb 3, 2016

anything different from #11485 ?

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode API Design labels Feb 3, 2016
@max-sixty
Copy link
Contributor Author

No that covers it!

Closing.

FWIW Series.filter seems a bit orphaned - not much in the docs, and its first arg items looks like nothing more than a slice. I wonder if this functionality could come from #11485.

@jreback
Copy link
Contributor

jreback commented Feb 3, 2016

@MaximilianR

yeah .filter is only on labels. its a bit of an odd spelling, as typically .filter is on data. though we use .query.

I think we have an issue about this somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

2 participants