Skip to content
Advertisement

Is there a way of selecting all records of a certain ID after randomly selecting the IDs?

I have a number of values per ID in this format:

JavaScript

I want to randomly select IDs but keep all values per ID, so for example, if I wanted to get 2 random IDs; the outcome would look like this:

JavaScript

Giving me, ID 2 & 5.

Advertisement

Answer

Use numpy.random.choice to select random values then select them.

JavaScript

Edit:

please read the comment from ouroboros1. choice has a parameter replace and it should be used.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement