1

I have the following dataframe with same value in 'nearest_beacon' column but different distance in 'vms_distance' column.

My Dataframe:

nearest_beacon  vms_distance associated
4548780      0.486456        vms
4548780      0.468065        vms
4548780      0.337609        vms
4548780      0.363601        vms
4548780      0.210566        vms
4548780      0.197327        vms*
4548780      0.285390        vms
4548780      0.216443        vms
4548780      0.441454        vms
4548780      0.337533        vms

I want to determine the 'associated' column just one row (*) which has 'vms' value considering it has the lower value in 'vms_distance' column, and the rest is 'no_vms'.

Expected Result:

nearest_beacon  vms_distance associated
4548780      0.486456        no_vms
4548780      0.468065        no_vms
4548780      0.337609        no_vms
4548780      0.363601        no_vms
4548780      0.210566        no_vms
4548780      0.197327        vms
4548780      0.285390        no_vms
4548780      0.216443        no_vms
4548780      0.441454        no_vms
4548780      0.337533        no_vms

closed as off-topic by BERA, LaughU, MrXsquared, Fran Raga, xunilk Aug 12 at 20:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • I'm sorry if it is off-topic question. I have moved this question to be asked at another site. – Suhendra Aug 13 at 3:36
1

You can do this by combining min() and apply() functions of pandas

DF['associated'] = DF['vms_distance'].apply(lambda x: 'vms' if x == DF['vms_distance'].min() else 'no_vms')

Not the answer you're looking for? Browse other questions tagged or ask your own question.