-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: Add %in% operator into compare w r (GH3850) #5875
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
Conversation
|
||
.. ipython:: python | ||
|
||
s = pd.Series(np.arange(5),index=np.arange(5)[::-1],dtype=np.float32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the np.arange(5)[::-1]
? Doesn't that make just more complicated for the reader to understand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it would, I was thinking of something...strange.
On 8 January 2014 22:01, Joris Van den Bossche notifications@github.comwrote:
In doc/source/comparison_with_r.rst:
+~~~~~~~~~~~~
+
+A common way to select data in R is using%in%
which is defined using the
+functionmatch
. The operator%in%
is used to return a logical vector
+indicating if there is a match or not:
+
+.. code-block:: r
+
- s <- 0:4
- s %in% c(2,4)
+The :meth:
~pandas.DataFrame.isin
method is similar to R%in%
operator:
+
+.. ipython:: python
+
- s = pd.Series(np.arange(5),index=np.arange(5)[::-1],dtype=np.float32)
Why the np.arange(5)[::-1]? Doesn't that make just more complicated for
the reader to understand?—
Reply to this email directly or view it on GitHubhttps://github.com//pull/5875/files#r8720691
.
Chapman
.. ipython:: python | ||
|
||
s = pd.Series(np.arange(5),dtype=np.float32) | ||
s.apply(lambda x: [2, 4].index(x) if x in [2,4] else np.nan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. pd.match() ignores it's na_sentinal argument, but otherwise it's a 1:1 match.
The _hashtable_algo
function it uses seems to be missing at least the int32 case, btw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm...looks kind of like Index.get_indexer (and the non_unique version). Never even knew this existed. Maybe should open an issue to see use case / doc or deprecate? I don't see it being used anywhere internally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DOC: Add %in% operator into compare w r (GH3850)
@chappers thanks again! |
Doesn't close #3850 but at least the
%in%
operator is now in the comparison with R docs. I've lumped it with thematch
function since thats the page you see the%in%
operator in the R docs http://finzi.psych.upenn.edu/R/library/base/html/match.html.