比如說有一個名為 df1 的dataframe
要統計某一列(比如說列名是city)中各個值出現的次數
#可以通過df.colname 來指定某個列,value_counts()在這里進行計數 df2 = df1.city.value_counts() print(df2)
- 1
- 2
- 3
還有一個是統計出現的個數: df.nunique(),
df.nunique() a 4 b 5 c 1 dtype: int64
https://blog.csdn.net/weixin_42389265/article/details/107013720?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param