0

I have two DataFrames as shown below:

data1 = {'Score1': [40,30,20], 'P1':[15.2, 13.3, 11.1], 'C1': [98,90,87]}
df1 = pd.DataFrame(data1)
df1

enter image description here

data2 = {'Score2': [35,33,26, 24], 'P2':[16.2, 14.7, 12.6, 11.4], 'C2': [98, 94, 86, 84]}
df2 = pd.DataFrame(data2)
df2

enter image description here

I would like to create a new DataFrame that contains Score1, Score2, P1, P2, C1, and C2. But P2 and C2 should be the closest value with P1 and C1, and Score2 should be ordered according to P2 and C2 order. I mean, row values should not be changed. For instance, the second row in a DataFrame 2 is Score2 = 33, P2 = 14.7 and C2 = 94. In the new data frame, this row should be the same. Also, I know row numbers are different and the new DataFrame has the row number of the DataFrame 1.

EDIT PART:

I think; the absolute value of the product of the difference of the P values and the difference of the C values should be minimum. In addition, the scores must progress by decreasing. For example, if we did not use the 2nd row and added the 3rd row to the DataFrame, we now have to continue from the 4th row for the next row.

Here is an example of expected output:

enter image description here

  • It could be simple if you give the expected output to explain your logic. Thanks – Corralien Mar 05 '22 at 16:16
  • I edited the question, and add an expected output. If you check the output, I pick a score 26 and skip score 33 for the second row, because P2 and C2 are closer to P1 and C1 in score 26 rather than 33. I hope I could explain it –  Mar 05 '22 at 16:45

0 Answers0