File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 11
11
from typing import (
12
12
TYPE_CHECKING ,
13
13
Literal ,
14
+ Union ,
14
15
cast ,
15
16
)
16
17
import warnings
@@ -839,7 +840,7 @@ def value_counts_internal(
839
840
values ,
840
841
sort : bool = True ,
841
842
ascending : bool = False ,
842
- normalize : bool = False ,
843
+ normalize : Union [ bool , str ] = False ,
843
844
bins = None ,
844
845
dropna : bool = True ,
845
846
) -> Series :
@@ -912,9 +913,11 @@ def value_counts_internal(
912
913
if sort :
913
914
result = result .sort_values (ascending = ascending )
914
915
915
- if normalize :
916
+ if normalize is True :
916
917
result = result / counts .sum ()
917
-
918
+ elif normalize == "keep" :
919
+ result = result .astype (str )+ '(' + (result / counts .sum ())\
920
+ .apply (lambda x : round (x , 6 )).astype (str )+ ')'
918
921
return result
919
922
920
923
Original file line number Diff line number Diff line change @@ -1086,7 +1086,7 @@ def value_counts(
1086
1086
self ,
1087
1087
sort = sort ,
1088
1088
ascending = ascending ,
1089
- normalize = normalize ,
1089
+ normalize : Union [ bool , str ] = False ,
1090
1090
bins = bins ,
1091
1091
dropna = dropna ,
1092
1092
)
You can’t perform that action at this time.
0 commit comments