Pandas Bootstrap
Statistical Bootstrap with Pandas made easy.
Installation
Usage
The module is very easy to use.
import bootstrap
- define statistic function:
def some_func(df: pd.DataFrame | pd.Series):
- get bootstrapped samples:
df.boot.get_samples(bfunc=some_func, B=100)
The return type of get_samples
is determined by the return type of the bfunc
function. See here for more details.
Quickstart
Below is a simple example of bootstrapping the mean of two columns.
import pandas as pd
import bootstrap
df = pd.DataFrame({
'a': [1, 2, 3, 4, 5],
'b': [6, 7, 8, 9, 10],
})
def mean_of_columns(df):
return df.mean(numeric_only=True)
sample_kwargs = dict(random_state=42)
df_bootstrap = df.boot.get_samples(bfunc=mean_of_columns, B=5, sample_kwargs=sample_kwargs)
which results in:
Read more in examples here.