Skip to content

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

Merged
merged 4 commits into from
Jun 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions doc/source/user_guide/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1532,9 +1532,8 @@ rows with ``DataFrame.loc``. For instance:
'A': [80, 23, np.nan, 22],
'B': [80, 55, 76, 67]})
df
melt = df.melt('col')
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]
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Member

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.])


Formerly this could be achieved with the dedicated ``DataFrame.lookup`` method
which was deprecated in version 1.2.0.
Expand Down