extensions
Extensions for pandas DataFrames and Series. Access with the boot
attribute of a DataFrame or Series.
Available after importing the package:
import bootstrap
df = pd.DataFrame(...)
df.boot.get_samples(...)
ser = pd.Series(...)
ser.boot.get_samples(...)
AccessorMixin
Common functionality for DataFrame and Series accessors.
Source code in bootstrap/extensions.py
get_samples(bfunc, B=100, sample_kwargs=None, parallel=None, **kwargs)
Get bootstrap samples of the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bfunc
|
BFUNC
|
Bootstrap function. |
required |
B
|
int
|
Number of bootstrap samples. |
100
|
sample_kwargs
|
Dict[str, Any]
|
Keyword arguments to pass to the sample method of the object. |
None
|
parallel
|
Optional[Parallel]
|
Joblib Parallel object. |
None
|
kwargs
|
kwargs
|
Keyword arguments to pass to the bootstrap function. |
{}
|
Returns:
Type | Description |
---|---|
Union[Series, DataFrame]
|
Bootstrap samples in a Series or DataFrame. Depends on the return type of the bootstrap function. |
Source code in bootstrap/extensions.py
DataFrameBootstrapAccessor
Bases: AccessorMixin
Bootstrap accessor for pandas DataFrames.
Examples:
Bootstrap the mean of each column in a DataFrame.
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)
df_bootstrap: pd.DataFrame = df.boot.get_samples(bfunc=mean_of_columns, B=100)
Source code in bootstrap/extensions.py
SeriesBootstrapAccessor
Bases: AccessorMixin
Bootstrap accessor for pandas Series.
Examples:
Bootstrap the mean of a Series.
import pandas as pd
import bootstrap
ser = pd.Series([1, 2, 3, 4, 5])
def mean_of_series(ser):
return ser.mean()
ser_bootstrap: pd.Series = ser.boot.get_samples(bfunc=mean_of_series, B=100)