samedi 22 mai 2021

How to randomly choose column value by Id number in Python?

How can I get a random single value by ID number based on a column value? I have a data frame (large data) similar to the following

ID city
a y
b x
a z
b w

Since I need to assign a unique city to each ID number, I would like to RANDOMLY choose between y and z for a and between x and w for b.

How can I do this?




Aucun commentaire:

Enregistrer un commentaire