-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC-Modified documentation for the issue GH42106 #42110
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
DOC-Modified documentation for the issue GH42106 #42110
Conversation
raghuabhishek
commented
Jun 18, 2021
- closes Use better example in pd.lookup replacement #42106
melt = melt.loc[melt['col'] == melt['variable'], 'value'] | ||
melt.reset_index(drop=True) | ||
idx, cols = pd.factorize(df['col']) | ||
df.reindex(cols, axis=1).to_numpy()[np.arange(len(df)), idx] |
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.
The text above the example will also need to be changed?
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.
Yes, you are right. I have modified the text which is there above the example,as per my understanding. Can you review it.
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.
show the result in the PR itself as this doesn't look to replicate
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.
On pandas 1.1.5:
In [1]: df = pd.DataFrame({'col': ["A", "A", "B", "B"],
...: ...: 'A': [80, 23, np.nan, 22],
...: ...: 'B': [80, 55, 76, 67]})
...:
In [2]: df.lookup(df.index, df['col'])
Out[2]: array([80., 23., 76., 67.])
the example on master:
In [2]: melt = df.melt('col')
...: melt = melt.loc[melt['col'] == melt['variable'], 'value']
...: melt.reset_index(drop=True)
Out[2]:
0 80.0
1 23.0
2 76.0
3 67.0
Name: value, dtype: float64
the example here:
In [3]: idx, cols = pd.factorize(df['col'])
...: df.reindex(cols, axis=1).to_numpy()[np.arange(len(df)), idx]
Out[3]: array([80., 23., 76., 67.])
doc/source/user_guide/indexing.rst
Outdated
and column labels, this can be achieved by ``pandas.factorize`` which extracts the distinct values of the intended column and can be indexed by passing the length of the dataframe to the | ||
``numpy.arange`` function and the distinct value array. For instance: |
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.
this is very complicated wording...how about
and column labels, this can be achieved by ``pandas.factorize`` which extracts the distinct values of the intended column and can be indexed by passing the length of the dataframe to the | |
``numpy.arange`` function and the distinct value array. For instance: | |
and column labels, this can be achieved by using ``pandas.factorize`` and NumPy indexing. For instance: |
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.
I have modified the file as per your suggestion.
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.
Looks good to me
Hi MarcoGorelli, I just wanted to know when can this PR be merged with the master/main. |
Commit for updating PR
Hi MarcoGorelli |
Hey @raghuabhishek yup, done
this looks good to me, but I'll leave it open for a bit in case others have comments |
Thanks @MarcoGorelli |
thanks @raghuabhishek |
@meeseeksdev backport 1.3.x |
Something went wrong ... Please have a look at my logs. |
…42161) Co-authored-by: Abhishek R <[email protected]>