获取列数之间的数值 - Pandas DataFrame [英] Get count of values across columns-Pandas DataFrame
本文介绍了获取列数之间的数值 - Pandas DataFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Pandas DataFrame,如下所示:
I have a Pandas DataFrame like following:
A B C
0 192.168.2.85 192.168.2.85 124.43.113.22
1 192.248.8.183 192.248.8.183 192.168.2.85
2 192.168.2.161 NaN 192.248.8.183
3 66.249.74.52 NaN 192.168.2.161
4 NaN NaN 66.249.74.52
我想在列之间获取某些值的计数。所以我的预期输出是这样的:
I want to get the count of a certain values across columns. So my expected output is something like:
IP Count
192.168.2.85 3 #Since this value is there in all coulmns
192.248.8.183 3
192.168.2.161 2
66.249.74.52 2
124.43.113.22 1
我知道如何跨行,但这样做列有点奇怪?帮我解决这个问题?谢谢。
I know how to this across rows, but doing this for columns is bit strange?Help me to solve this? Thanks.
推荐答案
stack ,然后使用 value_counts :
In [14]: df.stack().value_counts()
Out[14]:
192.248.8.183 3
192.168.2.85 3
66.249.74.52 2
192.168.2.161 2
124.43.113.22 1
dtype: int64
这篇关于获取列数之间的数值 - Pandas DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文