.value_counts()
时间: 2023-09-09 13:10:32 浏览: 94
pandas计数 value_counts()的使用
5星 · 资源好评率100%
The `.value_counts()` method is a pandas method that can be applied to a pandas Series or DataFrame object. It returns a new pandas Series object that contains the counts of unique values in the original Series or DataFrame object. The resulting Series object is sorted in descending order of the value counts. This method is often used to explore the distribution of values in a dataset.
Example:
```
import pandas as pd
data = pd.Series(['apple', 'banana', 'apple', 'orange', 'banana', 'apple'])
counts = data.value_counts()
print(counts)
```
Output:
```
apple 3
banana 2
orange 1
dtype: int64
```
阅读全文