Skip to content

Commit d4d424e

Browse files
author
Sarra Nebli
committed
Fixing CI errors 2
1 parent 03fddd9 commit d4d424e

File tree

1 file changed

+16
-41
lines changed

1 file changed

+16
-41
lines changed

janitor/functions/adorn.py

+16-41
Original file line numberDiff line numberDiff line change
@@ -183,47 +183,22 @@ def adorn_percentages(
183183
df, col1, col2, axis="row", fmt=True, include_ns=False, decimal_places=1
184184
):
185185
"""
186-
Adds percentages to a crosstab generated by tabyl, with options to format
187-
and include raw counts, and also control the behavior
188-
of adorn_pct_formatting and adorn_ns.
189-
190-
:param df: DataFrame used to generate the crosstab
191-
:param col1: First column to create the crosstab
192-
:param col2: Second column to create the crosstab
193-
:param axis: 'row' to add percentages by row, 'col' for column percentages,
194-
'all' for global percentages
195-
:param fmt: If True, formats percentages as strings
196-
(e.g., "12.5%"), else returns numeric values.
197-
:param include_ns: If True, includes raw counts alongside percentages.
198-
:param decimal_places: Number of decimal places for the percentages
199-
:param thousand_separator: Whether to add a thousand separator to the counts
200-
:param percent_format: Whether to format as percentages
201-
:return: DataFrame with percentages and optional formatting and raw counts
202-
203-
Example:
204-
Example:
205-
>>> data = {
206-
... "Category": ["A", "B", "A", "B", "A", "B"],
207-
... "Subcategory": ["X", "X", "Y", "Y", "X", "X"],
208-
... "Value": [1, 2, 3, 4, 5, 6],
209-
... }
210-
>>> df = pd.DataFrame(data)
211-
212-
>>> result = adorn_percentages(df, col1="Category",
213-
... col2="Subcategory", axis="row", fmt=True, include_ns=True)
214-
215-
>>> print(result)
216-
Category X Y
217-
A 20% (1) 80% (4)
218-
B 33.33% (2) 66.67% (4)
219-
220-
>>> result = adorn_percentages(df, col1="Category",
221-
... col2="Subcategory", axis="col", fmt=True)
222-
223-
>>> print(result)
224-
Category X Y
225-
A 33.33% (1) 50% (3)
226-
B 66.67% (2) 50% (3)
186+
Adds percentages to a crosstab generated by tabyl, with options to format
187+
and include raw counts, and also control the behavior
188+
of adorn_pct_formatting and adorn_ns.
189+
190+
:param df: DataFrame used to generate the crosstab
191+
:param col1: First column to create the crosstab
192+
:param col2: Second column to create the crosstab
193+
:param axis: 'row' to add percentages by row, 'col' for column percentages,
194+
'all' for global percentages
195+
:param fmt: If True, formats percentages as strings
196+
(e.g., "12.5%"), else returns numeric values.
197+
:param include_ns: If True, includes raw counts alongside percentages.
198+
:param decimal_places: Number of decimal places for the percentages
199+
:param thousand_separator: Whether to add a thousand separator to the counts
200+
:param percent_format: Whether to format as percentages
201+
:return: DataFrame with percentages and optional formatting and raw counts
227202
228203
"""
229204
# Generate the crosstab using tabyl with the two specified columns

0 commit comments

Comments
 (0)