qdesc 0.1.5__py3-none-any.whl → 0.1.6.1__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.

Potentially problematic release.


This version of qdesc might be problematic. Click here for more details.

qdesc/__init__.py CHANGED
@@ -1,6 +1,7 @@
1
- def desc(df):
2
- import pandas as pd
3
- import numpy as np
1
+ import pandas as pd
2
+ import numpy as np
3
+
4
+ def desc(df)
4
5
  from scipy.stats import anderson
5
6
  x = np.round(df.describe().T,2)
6
7
  x = x.iloc[:, [0,1,2,5,3,7]]
@@ -68,3 +69,36 @@ def freqdist_a(df, ascending=False):
68
69
  results.append(distribution)
69
70
  final_df = pd.concat(results, ignore_index=True)
70
71
  return final_df
72
+
73
+ def clean_sheet_name(name):
74
+ # Remove invalid characters
75
+ name = re.sub(r'[:\\/?*\[\]]', '', name)
76
+ # Limit to 31 characters
77
+ name = name.strip()[:31]
78
+ return name
79
+
80
+ def freqdist_to_excel(df, output_path, sort_by='Percentage', ascending=False, top_n=None):
81
+ used_names = set()
82
+ with pd.ExcelWriter(output_path, engine='xlsxwriter') as writer:
83
+ for column in df.select_dtypes(include=['object', 'category']).columns:
84
+ frequency_table = df[column].value_counts()
85
+ percentage_table = df[column].value_counts(normalize=True) * 100
86
+
87
+ distribution = pd.DataFrame({
88
+ 'Value': frequency_table.index,
89
+ 'Count': frequency_table.values,
90
+ 'Percentage': percentage_table.values
91
+ })
92
+ distribution = distribution.sort_values(by=sort_by, ascending=ascending)
93
+ if top_n is not None:
94
+ distribution = distribution.head(top_n)
95
+ # Generate safe sheet name
96
+ base_name = clean_sheet_name(column)
97
+ sheet_name = base_name
98
+ count = 1
99
+ while sheet_name.lower() in used_names:
100
+ sheet_name = f"{base_name[:28]}_{count}" # stay within 31 char limit
101
+ count += 1
102
+ used_names.add(sheet_name.lower())
103
+ distribution.to_excel(writer, sheet_name=sheet_name, index=False)
104
+ print(f"Frequency distributions written to {output_path}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: qdesc
3
- Version: 0.1.5
3
+ Version: 0.1.6.1
4
4
  Summary: Quick and Easy way to do descriptive analysis.
5
5
  Author: Paolo Hilado
6
6
  Author-email: datasciencepgh@proton.me
@@ -21,6 +21,7 @@ Be sure to run the following prior to using the "qd.desc" function:
21
21
 
22
22
  The qdesc package provides a quick and easy approach to do descriptive analysis for quantitative data.
23
23
 
24
+ ## qd.desc Function
24
25
  Run the function qd.desc(df) to get the following statistics:
25
26
  * count - number of observations
26
27
  * mean - measure of central tendency for normal distribution
@@ -33,17 +34,25 @@ Run the function qd.desc(df) to get the following statistics:
33
34
  * 5% crit_value - critical value for a 5% Significance Level
34
35
  * 1% crit_value - critical value for a 1% Significance Level
35
36
 
37
+ ## qd.freqdist Function
36
38
  Run the function qd.freqdist(df, "Variable Name") to easily create a frequency distribution for your chosen categorical variable with the following:
37
39
  * Variable Levels (i.e., for Sex Variable: Male and Female)
38
40
  * Counts - the number of observations
39
41
  * Percentage - percentage of observations from total.
40
42
 
43
+ ## qd.freqdist_a Function
41
44
  Run the function qd.freqdist_a(df, ascending = FALSE) to easily create frequency distribution tables, arranged in descending manner (default) or ascending (TRUE), for all
42
45
  the categorical variables in your data frame. The resulting table will include columns such as:
43
46
  * Variable levels (i.e., for Satisfaction: Very Low, Low, Moderate, High, Very High)
44
47
  * Counts - the number of observations
45
48
  * Percentage - percentage of observations from total.
46
49
 
50
+ ## qd.freqdist_to_excel Function
51
+ Run the function qd.freqdist_to_excel(df, "Name of file.xlsx", ascending = FALSE ) to easily create frequency distribution tables, arranged in descending manner (default) or ascending (TRUE), for all the categorical variables in your data frame and SAVED as separate sheets in the .xlsx File. The resulting table will include columns such as:
52
+ * Variable levels (i.e., for Satisfaction: Very Low, Low, Moderate, High, Very High)
53
+ * Counts - the number of observations
54
+ * Percentage - percentage of observations from total.
55
+
47
56
 
48
57
  Later versions will include data visualizations handy for exploring the distribution of the data set.
49
58
 
@@ -0,0 +1,6 @@
1
+ qdesc/__init__.py,sha256=1BwkmmnbM9RNIMlqOqCTg8jBmuUS7bGFGcQAiDwN80E,4438
2
+ qdesc-0.1.6.1.dist-info/LICENCE.txt,sha256=xdFo-Rt6I7EP7C_qrVeIBIcH_7mRGUh8sciJs2R8VmY,9684
3
+ qdesc-0.1.6.1.dist-info/METADATA,sha256=XvwvncOxF5FrXSG0jyTgzfANtsnkJbnFwDY-gaOUVqM,3782
4
+ qdesc-0.1.6.1.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
+ qdesc-0.1.6.1.dist-info/top_level.txt,sha256=JuSs1wWRGN77DVuq-SX-5P7m_mIZF0ikEVgPTBOrHb0,6
6
+ qdesc-0.1.6.1.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- qdesc/__init__.py,sha256=W8y3xolTQA7a6DaDRzuYDWk3qa89b1HEudXyKjwV6S8,2953
2
- qdesc-0.1.5.dist-info/LICENCE.txt,sha256=xdFo-Rt6I7EP7C_qrVeIBIcH_7mRGUh8sciJs2R8VmY,9684
3
- qdesc-0.1.5.dist-info/METADATA,sha256=FNjZ7v_Bv_hEvNmPyGUqGyfhE1CaFGILUFXVSz1-48A,3145
4
- qdesc-0.1.5.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
- qdesc-0.1.5.dist-info/top_level.txt,sha256=JuSs1wWRGN77DVuq-SX-5P7m_mIZF0ikEVgPTBOrHb0,6
6
- qdesc-0.1.5.dist-info/RECORD,,
File without changes