# Statistical bootstrapping in Python - is my code correct?

I wonder if my code for bootstrapping in Python is correctly coded or if there are logical flaws in it. It uses a 95% confidence interval. The code basically does the following for two datasets that contain 23 numerical values, respectively:

1. It takes 23 random values out of the dataset list that contains 23 values, respectively.
2. It then computes their standard deviation (SD) (part 1 of the script) or coefficient of variation (CV) (part 2 of the script).
3. The calculated SD (or CV) is then added to a predefined empty list: Core_bootstrapping = [] and Periphery_bootstrapping = [].
4. The process above runs 40.000 times so that 40.000 SD (or CV) results are copied into the corresponding list.
5. Finally, np.percentile is used to calculate the lower and upper end of a 95% confidence interval in a two-tailed test. Therefore, the cut-off is at 2.5 and 97.5%.

My code is shown below:

import numpy as np
import scipy as sp
import random

# Statistical signifiance of the Standard Deviation
Core_values = random.sample(range(1, 100), 23)
Periphery_values = random.sample(range(1, 50), 23)

Core_bootstrapping = []
for _ in range(40000):
Core_SD = np.random.choice(Core_values, size=23).std()
Core_bootstrapping.append(Core_SD)

Periphery_bootstrapping = []
for _ in range(40000):
Periphery_SD = np.random.choice(Core_values, size=23).std()
Periphery_bootstrapping.append(Periphery_SD)

Core_lower = np.percentile(Core_bootstrapping, q=2.5)
Core_upper = np.percentile(Core_bootstrapping, q=97.5)
Periphery_lower = np.percentile(Periphery_bootstrapping, q=2.5)
Periphery_upper = np.percentile(Periphery_bootstrapping, q=97.5)

print(f"Confidence interval SD Core:      {Core_lower} - {Core_upper}")
print(f"Confidence interval SD Periphery: {Periphery_lower} - {Periphery_upper}")

# Statistical signifiance of the Coefficient of Variation
Core_bootstrapping = []
for _ in range(40000):
Core_value = np.random.choice(Core_values, size=23)
Core_CV = np.std(Core_value) / np.mean(Core_value)
Core_bootstrapping.append(Core_CV)

Periphery_bootstrapping = []
for _ in range(40000):
Periphery_value = np.random.choice(Periphery_values, size=23)
Periphery_CV = np.std(Periphery_value) / np.mean(Periphery_value)
Periphery_bootstrapping.append(Periphery_CV)

Core_lower = np.percentile(Core_bootstrapping, q=2.5)
Core_upper = np.percentile(Core_bootstrapping, q=97.5)
Periphery_lower = np.percentile(Periphery_bootstrapping, q=2.5)
Periphery_upper = np.percentile(Periphery_bootstrapping, q=97.5)

print(f"\nConfidence interval CV Core:      {Core_lower} - {Core_upper}")
print(f"Confidence interval CV Periphery: {Periphery_lower} - {Periphery_upper}")


I have two questions concerning my script:

1. Does it correctly perform statistical bootstrapping? Or are there flaws in the script?
2. Would the following paradigmatic interpretation of my script’s result/output regarding statistical significance be correct?

Example result for CV:

Confidence interval CV Core:      0.1880055737390358 - 0.40767469603707585
Confidence interval CV Periphery: 0.35366221296723194 - 0.8804115795726065


In this case, the CV difference between Core and Periphery would be non-significant. Why? Because the upper end of core ends with 0.407, while the lower end of periphery starts with 0.353. Therefore, both confidence intervals overlap and their difference is not significant.

Thanks for any input.