Skip to content

Commit cf3b9b8

Browse files
authored
Update algorithms.py
Parameter updated. Normalization part updated accordingly.
1 parent b41e06a commit cf3b9b8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pandas/core/algorithms.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ def value_counts_internal(
839839
values,
840840
sort: bool = True,
841841
ascending: bool = False,
842-
normalize: bool = False,
842+
normalize: Union[bool, str] = False,
843843
bins=None,
844844
dropna: bool = True,
845845
) -> Series:
@@ -912,12 +912,14 @@ def value_counts_internal(
912912
if sort:
913913
result = result.sort_values(ascending=ascending)
914914

915-
if normalize:
915+
if normalize is True:
916+
# Handle normalization as usual
916917
result = result / counts.sum()
917-
918+
elif normalize == "keep":
919+
# Add normlized values to counts.
920+
result = result.astype(str)+'('+(result/counts.sum()).apply(lambda x: round(x, 6)).astype(str)+')'
918921
return result
919922

920-
921923
# Called once from SparseArray, otherwise could be private
922924
def value_counts_arraylike(
923925
values: np.ndarray, dropna: bool, mask: npt.NDArray[np.bool_] | None = None

0 commit comments

Comments
 (0)