Given the following two dataframes:
df1 = pd.DataFrame(data={'unicorn': ['blue', 'red', 'piNk'], 'size': [3, 4, 6]})
df2 = pd.DataFrame(data={'unicorn': ['red'], 'size': [2]})
df1:
unicorn size
0 blue 3
1 red 4
2 piNk 6
df2 (always has one row):
unicorn size
0 red 2
How can I compare the rows of both dataframes column-wise using custom comparison functions like this (simplified):
def unicorn_comparison(str1, str2) -> float:
return 100.0 if str1 == str2 else 0.0
and
def size_comparison(nr1, nr2) -> float:
return 100.0 if nr1 < nr2 else 0.0
Expected result:
unicorn size
0 0.0 0.0
1 100.0 0.0
2 0.0 0.0