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

Conversation

raghuabhishek
Copy link
Contributor

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

@mzeitlin11 mzeitlin11 added Docs Indexing Related to indexing on series/frames, not to indexes themselves labels Jun 18, 2021
Comment on lines 1526 to 1527
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:
Copy link
Member

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

Suggested change
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:

Copy link
Contributor Author

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.

Copy link
Member

@MarcoGorelli MarcoGorelli left a 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

@raghuabhishek
Copy link
Contributor Author

Looks good to me

Hi MarcoGorelli, I just wanted to know when can this PR be merged with the master/main.

@raghuabhishek raghuabhishek requested a review from jreback June 20, 2021 12:51
@raghuabhishek
Copy link
Contributor Author

Hi MarcoGorelli
Web/doc CI check was failing and as a result I had to update this PR with the master branch. Can you please approve the workflows.

@MarcoGorelli
Copy link
Member

Hey @raghuabhishek

yup, done

I just wanted to know when can this PR be merged with the master/main.

this looks good to me, but I'll leave it open for a bit in case others have comments

@raghuabhishek
Copy link
Contributor Author

Hey @raghuabhishek

yup, done

I just wanted to know when can this PR be merged with the master/main.

this looks good to me, but I'll leave it open for a bit in case others have comments

Thanks @MarcoGorelli

@jreback jreback added this to the 1.3 milestone Jun 21, 2021
@jreback jreback merged commit 00af20a into pandas-dev:master Jun 21, 2021
@jreback
Copy link
Contributor

jreback commented Jun 21, 2021

thanks @raghuabhishek

@jreback
Copy link
Contributor

jreback commented Jun 21, 2021

@meeseeksdev backport 1.3.x

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Jun 21, 2021
@lumberbot-app
Copy link

lumberbot-app bot commented Jun 21, 2021

Something went wrong ... Please have a look at my logs.

neinkeinkaffee pushed a commit to neinkeinkaffee/pandas that referenced this pull request Jun 21, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use better example in pd.lookup replacement
4 participants