有关pandas value_counts函数的说明 [英] Explanation about pandas value_counts function

查看:254
本文介绍了有关pandas value_counts函数的说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下这行是什么

Can someone please explain what does the line

result = data.apply(pd.value_counts).fillna(0)  

在这里吗?

import pandas as pd 
from pandas import Series, DataFrame

data = DataFrame({'Qu1': [1, 3, 4, 3, 4],
                  'Qu2': [2, 3, 1, 2, 3],
                  'Qu3': [1, 5, 2, 4, 4]})

result = data.apply(pd.value_counts).fillna(0)  

In [26]:data
Out[26]:
Qu1 Qu2 Qu3
0 1 2 1
1 3 3 5
2 4 1 2
3 3 2 4
4 4 3 4

In [27]:result
Out[28]:
Qu1 Qu2 Qu3
1 1 1 1
2 0 2 1
3 2 2 0
4 2 0 2
5 0 0 1

推荐答案

从文档中生成非空值的直方图.仅查看resultQu1列,我们可以知道原始列data.Qu1中有一个1、0 2,两个3,两个4和0 5.

From the docs, it produces a histogram of non-null values. Looking just at column Qu1 of result, we can tell that there is one 1, zero 2's, two 3's, two 4's, and zero 5's in the original column data.Qu1.

这篇关于有关pandas value_counts函数的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆