Using Sample() to Select Random Rows from Data
📖 Scenario: You work in a small bookstore. You have a list of books with their prices and want to randomly pick some books to check their condition.
🎯 Goal: Learn how to use the sample() method in pandas to select random rows from a dataset.
📋 What You'll Learn
Create a pandas DataFrame with book data
Set a variable for the number of random rows to select
Use the
sample() method to pick random rowsPrint the selected random rows
💡 Why This Matters
🌍 Real World
Random sampling helps quality check a few items from a large list without checking everything.
💼 Career
Data scientists often use random sampling to explore data or create training and testing sets.
Progress0 / 4 steps