If I understand correctly, you want to do two things:
- find the minimum B
per distinct A
, and
- make sure that they don't collide. You didn't specify what to do in case of collision, so I assume you just want to know if there is one.
The first can be achieved with Rarblack's answer (though you should use min
and not max
in your case).
For the second, you can use the .nunique()
method - see how many unique B
values are there (should be same as number of unique A
valuse)
#setup dataframe
df = pd.DataFrame.from_dict({
'A': [1,1,1,2,2,2,3,3,3],
'B': [0.1,0.2,0.3,0.2,0.5,0.3,0.8,0.6,0.1]
})
# find minimum
x = df.groupby('A')['B'].min()
# assert that there are no collisions:
if not (x.nunique() == len(x)):
print ("Conflicting values")