pandas-plots 0.15.10__py3-none-any.whl → 0.15.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pandas_plots/hlp.py +23 -28
- {pandas_plots-0.15.10.dist-info → pandas_plots-0.15.12.dist-info}/METADATA +1 -1
- pandas_plots-0.15.12.dist-info/RECORD +8 -0
- {pandas_plots-0.15.10.dist-info → pandas_plots-0.15.12.dist-info}/WHEEL +1 -1
- pandas_plots/.DS_Store +0 -0
- pandas_plots-0.15.10.dist-info/RECORD +0 -9
pandas_plots/hlp.py
CHANGED
@@ -21,49 +21,44 @@ from PIL import Image
|
|
21
21
|
|
22
22
|
URL_REGEX = r"^(?:http|ftp)s?://" # https://stackoverflow.com/a/1617386
|
23
23
|
|
24
|
-
|
24
|
+
|
25
|
+
def mean_confidence_interval(df, confidence=0.95, use_median=False):
|
25
26
|
"""
|
26
|
-
Calculate the mean or median and confidence interval.
|
27
|
-
|
27
|
+
Calculate the mean or median and confidence interval of the input dataframe.
|
28
|
+
Source: https://stackoverflow.com/questions/15033511/compute-a-confidence-interval-from-sample-data
|
28
29
|
|
29
30
|
Parameters:
|
30
|
-
|
31
|
+
df (array-like): The input dataframe.
|
31
32
|
confidence (float, optional): The confidence level for the interval. Defaults to 0.95.
|
32
|
-
use_median (bool, optional): If True, calculates median and
|
33
|
-
n_bootstraps (int, optional): Number of bootstrap samples for median CI. Only used if use_median is True.
|
33
|
+
use_median (bool, optional): If True, calculates median and confidence interval instead of mean. Defaults to False.
|
34
34
|
|
35
35
|
Returns:
|
36
|
-
tuple: A tuple containing the central value (mean or median),
|
36
|
+
tuple: A tuple containing the central value (mean or median), interval, lower bound, and upper bound.
|
37
37
|
"""
|
38
|
-
|
39
|
-
if
|
40
|
-
return
|
41
|
-
a = 1.0 * np.array(
|
38
|
+
df = to_series(df)
|
39
|
+
if df is None:
|
40
|
+
return None
|
41
|
+
a = 1.0 * np.array(df)
|
42
42
|
n = len(a)
|
43
43
|
|
44
44
|
if use_median:
|
45
|
-
if n < 2: # Cannot bootstrap with n < 2
|
46
|
-
return np.median(a), np.nan, np.nan, np.nan
|
47
|
-
|
48
|
-
bootstrapped_medians = []
|
49
|
-
for _ in range(n_bootstraps):
|
50
|
-
sample = np.random.choice(a, size=n, replace=True)
|
51
|
-
bootstrapped_medians.append(np.median(sample))
|
52
|
-
|
53
45
|
median = np.median(a)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
margin = (upper_bound - lower_bound) / 2 # Simple approximation for margin based on interval width
|
58
|
-
return median, margin, lower_bound, upper_bound
|
46
|
+
se = 1.253 * scipy.stats.sem(a) # Approximate standard error for median
|
47
|
+
margin = se * scipy.stats.t.ppf((1 + confidence) / 2.0, n - 1)
|
48
|
+
return median, margin, median - margin, median + margin
|
59
49
|
else:
|
60
|
-
mean = np.mean(a)
|
61
|
-
if n <= 1:
|
62
|
-
return mean, np.nan, np.nan, np.nan
|
63
|
-
se = scipy.stats.sem(a)
|
50
|
+
mean, se = np.mean(a), scipy.stats.sem(a)
|
64
51
|
margin = se * scipy.stats.t.ppf((1 + confidence) / 2.0, n - 1)
|
65
52
|
return mean, margin, mean - margin, mean + margin
|
66
53
|
|
54
|
+
# # * Alternative
|
55
|
+
# # from statistics import NormalDist
|
56
|
+
# def confidence_interval(data, confidence=0.95):
|
57
|
+
# dist = NormalDist.from_samples(data)
|
58
|
+
# z = NormalDist().inv_cdf((1 + confidence) / 2.)
|
59
|
+
# h = dist.stdev * z / ((len(data) - 1) ** .5)
|
60
|
+
# return dist.mean - h, dist.mean + h
|
61
|
+
|
67
62
|
|
68
63
|
def to_series(df) -> pd.Series | None:
|
69
64
|
"""
|
@@ -0,0 +1,8 @@
|
|
1
|
+
pandas_plots/__init__.py,sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855,0
|
2
|
+
pandas_plots/hlp.py,sha256=912aa818c11a3ad0bde30b534bb08c157320a6dbfedad48e31fe599bb7ae8692,20838
|
3
|
+
pandas_plots/pls.py,sha256=66afca26f49471609fbb3f870f0d63e12e40be9c14ce83665cd03f69901abe15,65548
|
4
|
+
pandas_plots/tbl.py,sha256=489d92b8b4b2664dae89addda1512da8accb5a63e6e2710c58e9507c95a414f1,33571
|
5
|
+
pandas_plots/ven.py,sha256=db1dc00a8daf49f3b7aba7eff94743434875489cadf160a1046804e520c27429,11673
|
6
|
+
pandas_plots-0.15.12.dist-info/WHEEL,sha256=a51d7af6bb8356f1000fb3d205aba975eca53e14c9e011c620094d822eb4863c,79
|
7
|
+
pandas_plots-0.15.12.dist-info/METADATA,sha256=2b6fcda11a6ea6b648fbb6d0854607a4382c9c7d9c95fc109c51322cb16cd57c,8000
|
8
|
+
pandas_plots-0.15.12.dist-info/RECORD,,
|
pandas_plots/.DS_Store
DELETED
Binary file
|
@@ -1,9 +0,0 @@
|
|
1
|
-
pandas_plots/.DS_Store,sha256=e90dd27d76d30869e4b3244fc211ad13e2acf715d00902d8cc1501e123fbf26d,6148
|
2
|
-
pandas_plots/__init__.py,sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855,0
|
3
|
-
pandas_plots/hlp.py,sha256=cfcaeb54d6c7f6a32885d5cf4fe164b0ff959133a32346c6163e3b4b0e69dda6,21141
|
4
|
-
pandas_plots/pls.py,sha256=66afca26f49471609fbb3f870f0d63e12e40be9c14ce83665cd03f69901abe15,65548
|
5
|
-
pandas_plots/tbl.py,sha256=489d92b8b4b2664dae89addda1512da8accb5a63e6e2710c58e9507c95a414f1,33571
|
6
|
-
pandas_plots/ven.py,sha256=db1dc00a8daf49f3b7aba7eff94743434875489cadf160a1046804e520c27429,11673
|
7
|
-
pandas_plots-0.15.10.dist-info/WHEEL,sha256=2b400f346628f0064eb5bbf656b39df8dfcb092437ab08244409d295749b81a3,78
|
8
|
-
pandas_plots-0.15.10.dist-info/METADATA,sha256=284ec43a99fc30ba4d564cd114475a743cce675fa21cf1bdfb265d9aa1644ce0,8000
|
9
|
-
pandas_plots-0.15.10.dist-info/RECORD,,
|