Skip to content
Advertisement

Extract corresponding df value with reference from another df

There are 2 dataframes with 1 to 1 correspondence. I can retrieve an idxmax from all columns in df1.

Input:

JavaScript

Output: df1, df2 and df

JavaScript

Now I want to create a df which contains 3 columns

Desired Output df:

JavaScript

What are the best options to extract the corresponding values from df2?

Advertisement

Answer

Your main problem is matching the columns between df1 and df2. Let’s rename them properly, melt both dataframes, merge and extract:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement