I'm trying to find the "best in class", with each class being a whole dollar amount in prices
and "best" being maximum value
like so:
example = pd.DataFrame({
"values": [1, 2, 3, 3, 3, 4, 4, 5, 6, 6, 7, 7, 7, 8,8,8,8,8, 9 ],
"prices": [1.1, 2.2, 3.31, 3.32, 3.33, 4.1, 4.2, 5.1, 6.1, 6.2, 7.1, 7.2, 7.3, 8.1, 8.2, 8.3, 8.4, 8.5, 9.1]
})
Is there a way to compare the value of a column against multiple? Perhaps something like:
example["is_best"] = np.where(example["prices"] < all(example[example[values]])
Expected output:
values prices is_best
0 1 1.10 1
1 2 2.20 1
2 3 3.31 1
3 3 3.32 0
4 3 3.33 0
5 4 4.10 1
6 4 4.20 0
7 5 5.10 0
8 6 6.10 1
9 6 6.20 0
Caveat: There will be other columns with varying data in them.