1. Learn
  2. /
  3. Courses
  4. /
  5. Writing Efficient Code with pandas

Connected

Exercise

Random row selection

In this exercise, you will compare the two methods described for selecting random rows (entries) with replacement in a pandas DataFrame:

  • The built-in pandas function .random()
  • The NumPy random integer number generator np.random.randint()

Generally, in the fields of statistics and machine learning, when we need to train an algorithm, we train the algorithm on the 75% of the available data and then test the performance on the remaining 25% of the data.

For this exercise, we will randomly sample the 75% percent of all the played poker hands available, using each of the above methods, and check which method is more efficient in terms of speed.

Instructions 1/3

undefined XP
    1
    2
    3
  • Randomly select 75% of the rows of the poker dataset using the np.random.randint() method.