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 1111from typing import (
1212 TYPE_CHECKING ,
1313 Literal ,
14+ Union ,
1415 cast ,
1516)
1617import warnings
@@ -839,7 +840,7 @@ def value_counts_internal(
839840 values ,
840841 sort : bool = True ,
841842 ascending : bool = False ,
842- normalize : bool = False ,
843+ normalize : Union [ bool , str ] = False ,
843844 bins = None ,
844845 dropna : bool = True ,
845846) -> Series :
@@ -912,9 +913,11 @@ def value_counts_internal(
912913 if sort :
913914 result = result .sort_values (ascending = ascending )
914915
915- if normalize :
916+ if normalize is True :
916917 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 )+ ')'
918921 return result
919922
920923
Original file line number Diff line number Diff line change @@ -1086,7 +1086,7 @@ def value_counts(
10861086 self ,
10871087 sort = sort ,
10881088 ascending = ascending ,
1089- normalize = normalize ,
1089+ normalize : Union [ bool , str ] = False ,
10901090 bins = bins ,
10911091 dropna = dropna ,
10921092 )
You can’t perform that action at this time.
0 commit comments