As @user48956 commented on accepted answer, is much faster to sample over the index using numpy.random.choice

np.random.seed(42)
df = pd.DataFrame(np.random.randint(0,100,size=(10000000, 4)), columns=list('ABCD'))
%time df.sample(100000).index
print(_)
%time pd.Index(np.random.choice(df.index, 100000))
Wall time: 710 ms
Int64Index([7141956, 9256789, 1919656, 2407372, 9181191, 2474961, 2345700,
            4394530, 8864037, 6096638,
            ...
             471501, 3616956, 9397742, 6896140,  670892, 9546169, 4146996,
            3465455, 7748682, 5271367],
           dtype='int64', length=100000)
Wall time: 6.05 ms

Int64Index([7141956, 9256789, 1919656, 2407372, 9181191, 2474961, 2345700,
            4394530, 8864037, 6096638,
            ...
             471501, 3616956, 9397742, 6896140,  670892, 9546169, 4146996,
            3465455, 7748682, 5271367],
           dtype='int64', length=100000)
Answer from Ameb on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.sample.html
pandas.Series.sample — pandas 3.0.5 documentation
Extract 3 random elements from the Series df['num_legs']: Note that we use random_state to ensure the reproducibility of the examples. >>> df["num_legs"].sample(n=3, random_state=1) fish 0 spider 8 falcon 2 Name: num_legs, dtype: int64
🌐
w3resource
w3resource.com › pandas › series › series-sample.php
Pandas Series: sample() function - w3resource
May 13, 2026 - Example - Extract 3 random elements from the Series df['num_legs']: Note that we use random_state to ensure the reproducibility of the examples: ... import numpy as np import pandas as pd df = pd.DataFrame({'num_legs': [2, 4, 8, 0], 'num_wings': [2, 0, 0, 0], 'num_specimen_seen': [8, 2, 1, 6]}, index=['sparrow', 'cat', 'spider', 'snake']) df['num_legs'].sample(n=3, random_state=1)
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › python-pandas-series-sample
Python | Pandas Series.sample() - GeeksforGeeks
February 7, 2019 - Example #2: Use Series.sample() function to draw random sample of the values from the given Series object. ... # importing pandas as pd import pandas as pd # Creating the Series sr = pd.Series([100, 25, 32, 118, 24, 65]) # Create the Index index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp'] # set the index sr.index = index_ # Print the series print(sr) Output : Now we will use Series.sample() function to select a random sample of size equivalent to 25% of the size of the given Series object...
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.23.4 › generated › pandas.Series.sample.html
pandas.Series.sample — pandas 0.23.4 documentation
Return a random sample of items from an axis of object. You can use random_state for reproducibility. ... >>> s = pd.Series(np.random.randn(50)) >>> s.head() 0 -0.038497 1 1.820773 2 -0.972766 3 -1.598270 4 -1.095526 dtype: float64 >>> df = pd.DataFrame(np.random.randn(50, 4), columns=list('ABCD')) ...
🌐
W3Schools
w3schools.com › python › pandas › pandas_series.asp
Pandas Series
Data sets in Pandas are usually multi-dimensional tables, called DataFrames. Series is like a column, a DataFrame is the whole table.
🌐
pandas
pandas.pydata.org › pandas-docs › dev › reference › api › pandas.Series.sample.html
pandas.Series.sample — pandas 3.0.0.dev0+2650.g607e489bd1 documentation
Extract 3 random elements from the Series df['num_legs']: Note that we use random_state to ensure the reproducibility of the examples. >>> df["num_legs"].sample(n=3, random_state=1) fish 0 spider 8 falcon 2 Name: num_legs, dtype: int64
Find elsewhere
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.24.0rc1 › api › generated › pandas.Series.sample.html
pandas.Series.sample — pandas 0.24.0rc1 documentation
Generates a random sample from a given 1-D numpy array. ... >>> df = pd.DataFrame({'num_legs': [2, 4, 8, 0], ... 'num_wings': [2, 0, 0, 0], ... 'num_specimen_seen': [10, 2, 1, 8]}, ... index=['falcon', 'dog', 'spider', 'fish']) >>> df num_legs num_wings num_specimen_seen falcon 2 2 10 dog 4 ...
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.Series.sample.html
pandas.Series.sample — pandas 3.1.0.dev0+1159.gd7b577e035 documentation
Extract 3 random elements from the Series df['num_legs']: Note that we use random_state to ensure the reproducibility of the examples. >>> df["num_legs"].sample(n=3, random_state=1) fish 0 spider 8 falcon 2 Name: num_legs, dtype: int64
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.pandas › api › pyspark.pandas.Series.sample.html
pyspark.pandas.Series.sample — PySpark 4.1.1 documentation
Return a random sample of items from an axis of object. Please call this function using named argument by specifying the frac argument. You can use random_state for reproducibility. However, note that different from pandas, specifying a seed in pandas-on-Spark/Spark does not guarantee the sampled ...
🌐
w3resource
w3resource.com › python-exercises › pandas › index-data-series.php
Pandas Data Series: Exercises, Practice, Solution
Write a Pandas program to add, subtract, multiple and divide two Pandas Series. Sample Series: [2, 4, 6, 8, 10], [1, 3, 5, 7, 9] Click me to see the sample solution
🌐
w3resource
w3resource.com › pandas › series › pandas-series-sample.html
pandas-series-sample
import numpy as np import pandas as pd · In [2]: df = pd.DataFrame({'num_legs': [2, 4, 8, 0], 'num_wings': [2, 0, 0, 0], 'num_specimen_seen': [8, 2, 1, 6]}, index=['sparrow', 'cat', 'spider', 'snake']) df · Out[2]: Extract 3 random elements from the Series df['num_legs']: Note that we use ...
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Random sampling from DataFrame with sample() | note.nkmk.me
May 22, 2022 - You can get a random sample from pandas.DataFrame and Series by the sample() method. This is useful for checking data in a large pandas.DataFrame, Series. pandas.DataFrame.sample — pandas 1.4.2 docum ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas series tutorial with examples
Pandas Series Tutorial with Examples - Spark By {Examples}
June 19, 2025 - Pandas Series Introduction This is a beginner’s guide of Python pandas Series Tutorial where you will learn what is pandas Series? its features,
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas series sample() function
Pandas Series sample() Function - Spark By {Examples}
July 31, 2024 - In Pandas, the sample() function is used to obtain a random sample of items from a Pandas Series. It allows you to specify the number of items
🌐
Towards Data Science
towardsdatascience.com › home › latest › 20 examples to master pandas series
20 Examples to Master Pandas Series | Towards Data Science
January 29, 2025 - It returns the Series with boolean values indicating missing values with True. ... We can count the number of missing values by chaining the sum function with the isna function. ... In data analysis, we are most likely to have numerical values. Pandas is highly capable of manipulating numerical data.
🌐
Databricks
api-docs.databricks.com › python › pyspark › latest › pyspark.pandas › api › pyspark.pandas.Series.sample.html
pyspark.pandas.Series.sample — PySpark master documentation
Series.sample(n: Optional[int] = None, frac: Optional[float] = None, replace: bool = False, random_state: Optional[int] = None, ignore_index: bool = False) → pyspark.pandas.series.Series¶