@@ -1008,7 +1008,7 @@ def map_f(values, f):
1008
1008
def value_counts (self , normalize = False , sort = True , ascending = False ,
1009
1009
bins = None , dropna = True ):
1010
1010
"""
1011
- Returns object containing counts of unique values.
1011
+ Return a Series containing counts of unique values.
1012
1012
1013
1013
The resulting object will be in descending order so that the
1014
1014
first element is the most frequently-occurring element.
@@ -1020,18 +1020,69 @@ def value_counts(self, normalize=False, sort=True, ascending=False,
1020
1020
If True then the object returned will contain the relative
1021
1021
frequencies of the unique values.
1022
1022
sort : boolean, default True
1023
- Sort by values
1023
+ Sort by values.
1024
1024
ascending : boolean, default False
1025
- Sort in ascending order
1025
+ Sort in ascending order.
1026
1026
bins : integer, optional
1027
1027
Rather than count values, group them into half-open bins,
1028
- a convenience for pd.cut, only works with numeric data
1028
+ a convenience for `` pd.cut`` , only works with numeric data.
1029
1029
dropna : boolean, default True
1030
1030
Don't include counts of NaN.
1031
1031
1032
1032
Returns
1033
1033
-------
1034
1034
counts : Series
1035
+
1036
+ See Also
1037
+ --------
1038
+ Series.count: number of non-NA elements in a Series
1039
+ DataFrame.count: number of non-NA elements in a DataFrame
1040
+
1041
+ Examples
1042
+ --------
1043
+ >>> index = pd.Index([3, 1, 2, 3, 4, np.nan])
1044
+ >>> index.value_counts()
1045
+ 3.0 2
1046
+ 4.0 1
1047
+ 2.0 1
1048
+ 1.0 1
1049
+ dtype: int64
1050
+
1051
+ With `normalize` set to `True`, returns the relative frequency by
1052
+ dividing all values by the sum of values.
1053
+
1054
+ >>> s = pd.Series([3, 1, 2, 3, 4, np.nan])
1055
+ >>> s.value_counts(normalize=True)
1056
+ 3.0 0.4
1057
+ 4.0 0.2
1058
+ 2.0 0.2
1059
+ 1.0 0.2
1060
+ dtype: float64
1061
+
1062
+ **bins**
1063
+
1064
+ Bins can be useful for going from a continuous variable to a
1065
+ categorical variable; instead of counting unique
1066
+ apparitions of values, divide the index in the specified
1067
+ number of half-open bins.
1068
+
1069
+ >>> s.value_counts(bins=3)
1070
+ (2.0, 3.0] 2
1071
+ (0.996, 2.0] 2
1072
+ (3.0, 4.0] 1
1073
+ dtype: int64
1074
+
1075
+ **dropna**
1076
+
1077
+ With `dropna` set to `False` we can also see NaN index values.
1078
+
1079
+ >>> s.value_counts(dropna=False)
1080
+ 3.0 2
1081
+ NaN 1
1082
+ 4.0 1
1083
+ 2.0 1
1084
+ 1.0 1
1085
+ dtype: int64
1035
1086
"""
1036
1087
from pandas .core .algorithms import value_counts
1037
1088
result = value_counts (self , sort = sort , ascending = ascending ,
0 commit comments