File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff 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
922924def value_counts_arraylike (
923925 values : np .ndarray , dropna : bool , mask : npt .NDArray [np .bool_ ] | None = None
You can’t perform that action at this time.
0 commit comments