-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
Closed
Labels
API DesignIndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode
Description
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: int64Instead, 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)
Metadata
Metadata
Assignees
Labels
API DesignIndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesReshapingConcat, Merge/Join, Stack/Unstack, ExplodeConcat, Merge/Join, Stack/Unstack, Explode