Skip to content
FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS
Close
Beyond Knowledge Innovation

Beyond Knowledge Innovation

Where Data Unveils Possibilities

  • Home
  • AI & ML Insights
  • Machine Learning
    • Supervised Learning
      • Introduction
      • Regression
      • Classification
    • Unsupervised Learning
      • Introduction
      • Clustering
      • Association
      • Dimensionality Reduction
    • Reinforcement Learning
    • Generative AI
  • Knowledge Base
    • Introduction To Python
    • Introduction To Data
    • Introduction to EDA
  • References
HomeImplementationEDAGet a random sample from your dataset
EDA Python

Get a random sample from your dataset

March 7, 2024March 7, 2024CEO 150 views

To grab random sample from a dataset in Python, you can use the pandas library. Assuming your dataset is stored in a pandas DataFrame, you can use the sample method to randomly select rows.

Here’s an example:

import pandas as pd

data = {
    'Column1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
    'Column2': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L']
}

your_dataset = pd.DataFrame(data)

# Grabbing random 5 rows
random_5_rows = your_dataset.sample(n=5, random_state=1)

# Display the result
print(random_5_rows)

In this example, n=5 specifies the number of rows to sample, and random_state is set to ensure reproducibility.

    Column1 Column2
10       11       K
9        10       J
0         1       A
8         9       I
5         6       F
pandas, random, sample

Post navigation

Previous Post
Previous post: Receiver Operating Characteristic (ROC) and Area Under Curve (AUC)
Next Post
Next post: Import your functions library to a Google Colab notebook

You Might Also Like

No image
Quantile-based discretization of continuous variables
April 29, 2024 Comments Off on Quantile-based discretization of continuous variables
No image
How-to: stack up two plots using the…
February 11, 2024 Comments Off on How-to: stack up two plots using the subplot function
No image
How-to: give a specific sorting order to…
February 7, 2024 Comments Off on How-to: give a specific sorting order to categorical values
No image
How-to: clean a dataset
February 6, 2024 Comments Off on How-to: clean a dataset
No image
How-to: formatting options for floating-point numbers in…
February 2, 2024 Comments Off on How-to: formatting options for floating-point numbers in Pandas
  • Recent
  • Popular
  • Random
  • No image
    7 months ago Low-Rank Factorization
  • No image
    7 months ago Perturbation Test for a Regression Model
  • No image
    7 months ago Calibration Curve for Classification Models
  • No image
    March 15, 20240Single linkage hierarchical clustering
  • No image
    April 17, 20240XGBoost (eXtreme Gradient Boosting)
  • No image
    April 17, 20240Gradient Boosting
  • No image
    March 7, 2024Feature Importance in Decision Tree
  • No image
    February 28, 2024Linear regression model coefficients
  • No image
    January 19, 2024How to Save Your Python Objects in…
  • Implementation (55)
    • EDA (4)
    • Neural Networks (10)
    • Supervised Learning (26)
      • Classification (17)
      • Linear Regression (8)
    • Unsupervised Learning (11)
      • Clustering (8)
      • Dimensionality Reduction (3)
  • Knowledge Base (44)
    • Python (27)
    • Statistics (6)
May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Oct    

We are on

FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS

Subscribe

© 2025 Beyond Knowledge Innovation
FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS