Issue
When I'm exploring data in an ad hoc way, I often have code like this:
X = (adj_all.o.diff(1) / adj_none.o.diff(1)).diff(1)
print(X[X > 0])
Is there a way to do this in a single line in an easy way? The following works but is verbose:
(adj_all.o.diff(1) / adj_none.o.diff(1)).diff(1)[(adj_all.o.diff(1) / adj_none.o.diff(1)).diff(1) > 0]
I want something like this:
(adj_all.o.diff(1) / adj_none.o.diff(1)).diff(1)[self > 0]
Note that this isn't production code. It is part of ad hoc exploration where iteration speed is important to results, which is why I wish to be able to do this common thing in a single line.
Solution
You can use pipe
:
(adj_all.o.diff(1) / adj_none.o.diff(1)).diff(1).pipe(lambda x: x[x>0])
Answered By - enke
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.