I have two data frames, df and df2, they correspond. Now, based on the first df data frame, I want to get the 3 smallest value in one row and return the corresponding column name (in this case, for example, “X” or “Y” or “Z” or “T”). So I can get a new dataframe df3.
df = pd.DataFrame({
'X': [21, 2, 43, 44, 56, 67, 7, 38, 29, 130],
'Y': [101, 220, 330, 140, 250, 10, 207, 320, 420, 50],
'Z': [20, 128, 136, 144, 312, 10, 82, 63, 42, 12],
'T': [2, 32, 4, 424, 256, 167, 27, 38, 229, 30]
}, index=list('ABCDEFGHIJ'))
df2 = pd.DataFrame({
'X': [0.5, 0.12,0.43, 0.424, 0.65,0.867,0.17,0.938,0.229,0.113],
'Y': [0.1,2.201,0.33,0.140,0.525,0.31,0.20,0.32,0.420,0.650],
'Z': [0.20,0.128,0.136,0.2144,0.5312,0.61,0.82,0.363,0.542,0.512],
'T':[0.52, 0.232,0.34, 0.6424, 0.6256,0.3167,0.527,0.38,0.4229,0.73]
},index=list('ABCDEFGHIJ'))
Also, I want to get another dataframe df4 that matches df3 in df2, which means that in df the string ['A'] (2,20,21) is the 3 smallest value, so in the string df4 ['A'] I want to get (0,52,0,2,0,5) from df2.
Thank.