I have a pandas dataframe as follows:
| col_1 | col_2 | col_3 | col_4 | col_5 | col_6 |
|---|---|---|---|---|---|
| a | b | c | d | e | f |
| a | b | c | h | j | f |
| a | b | c | k | e | l |
| x | b | c | d | e | f |
And I want to get a score for all the rows to see which of them are mos similar to the first one considering:
- First, the number of columns with same values between the first row and the row we are considering
- If two rows have the same number of equal value compared to first row, consider digit importance, that is, go from left to right in column order and give more importance to those rows whose matching columns are the most left-ones.
In the example above, the score should be something in the following order:
- 4th row (the last one), as it has 4 columns values in common with row 1
- 3rd row, as it has 3 elements in common with row 1 and the non-matching columns are columns 4 and 6, while in row 2 these non matching columns are 4 and 5
- 2nd row, as it has the same number of coincidences than row 3 but the column 5 is matching in row 3 but not in row 2
I want to solve this using a lambda function that assigns the score to ecah row of the dataframe, given the row one as a constant.