From 316262f60e8fa62d768d7d31224bb14308772096 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 18 Jun 2021 23:31:52 +0530 Subject: [PATCH 1/3] DOC-Modified documentation for the issue GH42106 --- doc/source/user_guide/indexing.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index 862aef8ceab34..23f8d5ec4022a 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -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] Formerly this could be achieved with the dedicated ``DataFrame.lookup`` method which was deprecated in version 1.2.0. From 9dd6e41f4c2d237bef47a084daa7985671c85b89 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 19 Jun 2021 01:01:56 +0530 Subject: [PATCH 2/3] DOC-Modified documentation for the issue GH42106 --- doc/source/user_guide/indexing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index 23f8d5ec4022a..62414c82224b6 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -1523,8 +1523,8 @@ Looking up values by index/column labels ---------------------------------------- Sometimes you want to extract a set of values given a sequence of row labels -and column labels, this can be achieved by ``DataFrame.melt`` combined by filtering the corresponding -rows with ``DataFrame.loc``. For instance: +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: .. ipython:: python From d3364d78bd853097f86104280ee561bd0dfd3f5c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 19 Jun 2021 12:47:12 +0530 Subject: [PATCH 3/3] DOC-Modified documentation for the issue GH42106 --- doc/source/user_guide/indexing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index 62414c82224b6..584dd0f52ae28 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -1523,8 +1523,8 @@ Looking up values by index/column labels ---------------------------------------- Sometimes you want to extract a set of values given a sequence of row labels -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 ``pandas.factorize`` and NumPy indexing. +For instance: .. ipython:: python