File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1049,6 +1049,34 @@ def value_counts(
1049
1049
4.0 1
1050
1050
NaN 1
1051
1051
Name: count, dtype: int64
1052
+
1053
+ **Categorical Dtypes**
1054
+
1055
+ Rows with categorical type will be counted as one group
1056
+ if they have same categories and order.
1057
+ In the example below, even though ``a``, ``c``, and ``d``
1058
+ all have the same data types of ``category``,
1059
+ only ``c`` and ``d`` will be counted as one group
1060
+ since ``a`` doesn't have the same categories.
1061
+
1062
+ >>> df = pd.DataFrame({"a": [1], "b": ["2"], "c": [3], "d": [3]})
1063
+ >>> df = df.astype({"a": "category", "c": "category", "d": "category"})
1064
+ >>> df
1065
+ a b c d
1066
+ 0 1 2 3 3
1067
+
1068
+ >>> df.dtypes
1069
+ a category
1070
+ b object
1071
+ c category
1072
+ d category
1073
+ dtype: object
1074
+
1075
+ >>> df.dtypes.value_counts()
1076
+ category 2
1077
+ category 1
1078
+ object 1
1079
+ Name: count, dtype: int64
1052
1080
"""
1053
1081
return algorithms .value_counts_internal (
1054
1082
self ,
You can’t perform that action at this time.
0 commit comments