Return a Series containing counts of each category. Every category will have an entry, even those with a count of 0. Parameters ---------- dropna : bool, default True Don't include counts of NaN. Returns ------- counts :
(self, dropna: bool = True)
| 1867 | notnull = notna |
| 1868 | |
| 1869 | def value_counts(self, dropna: bool = True) -> Series: |
| 1870 | """ |
| 1871 | Return a Series containing counts of each category. |
| 1872 | |
| 1873 | Every category will have an entry, even those with a count of 0. |
| 1874 | |
| 1875 | Parameters |
| 1876 | ---------- |
| 1877 | dropna : bool, default True |
| 1878 | Don't include counts of NaN. |
| 1879 | |
| 1880 | Returns |
| 1881 | ------- |
| 1882 | counts : Series |
| 1883 | |
| 1884 | See Also |
| 1885 | -------- |
| 1886 | Series.value_counts |
| 1887 | """ |
| 1888 | from pandas import ( |
| 1889 | CategoricalIndex, |
| 1890 | Series, |
| 1891 | ) |
| 1892 | |
| 1893 | code, cat = self._codes, self.categories |
| 1894 | ncat, mask = (len(cat), code >= 0) |
| 1895 | ix, clean = np.arange(ncat), mask.all() |
| 1896 | |
| 1897 | if dropna or clean: |
| 1898 | obs = code if clean else code[mask] |
| 1899 | count = np.bincount(obs, minlength=ncat or 0) |
| 1900 | else: |
| 1901 | count = np.bincount(np.where(mask, code, ncat)) |
| 1902 | ix = np.append(ix, -1) |
| 1903 | |
| 1904 | ix = coerce_indexer_dtype(ix, self.dtype.categories) |
| 1905 | ix_categorical = self._from_backing_data(ix) |
| 1906 | |
| 1907 | return Series( |
| 1908 | count, |
| 1909 | index=CategoricalIndex(ix_categorical), |
| 1910 | dtype="int64", |
| 1911 | name="count", |
| 1912 | copy=False, |
| 1913 | ) |
| 1914 | |
| 1915 | # error: Argument 2 of "_empty" is incompatible with supertype |
| 1916 | # "NDArrayBackedExtensionArray"; supertype defines the argument type as |
no test coverage detected