@@ -197,33 +197,6 @@ def adorn_percentages(
197
197
:param percent_format: Whether to format as percentages
198
198
:return: DataFrame with percentages and optional formatting and raw counts
199
199
200
- >>> data = {
201
- ... "Category": ["A", "A", "B", "B", "C", "C", "A", "B", "C", "A"],
202
- ... "Subcategory": ["X", "Y", "X", "Y", "X", "Y", "X", "Y", "X", "X"],
203
- ... "Value": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
204
- ... }
205
- >>> df = pd.DataFrame(data)
206
-
207
- Example of axis=row
208
- >>> result = adorn_percentages(
209
- ... df, "Category", "Subcategory", axis="row", fmt=True, include_ns=True
210
- ... )
211
- >>> print(result)
212
- Subcategory Category X Y
213
- 0 A 3 (75.0%) 1 (25.0%)
214
- 1 B 1 (33.3%) 2 (66.7%)
215
- 2 C 2 (66.7%) 1 (33.3%)
216
- Total NaN 6 (60.0%) 4 (40.0%)
217
-
218
- >>> result = adorn_percentages(
219
- ... df, "Category", "Subcategory", axis="all", fmt=True, include_ns=True
220
- ... )
221
- >>> print(result)
222
- Subcategory Category X Y
223
- 0 A 3 (42.9%) 1 (25.0%)
224
- 1 B 1 (14.3%) 2 (50.0%)
225
- 2 C 2 (28.6%) 1 (25.0%)
226
- Total NaN 6 (100.0%) 4 (100.0%)
227
200
"""
228
201
# Generate the crosstab using tabyl with the two specified columns
229
202
pivot = pd .pivot_table (
0 commit comments