简体   繁体   English

遍历 Panda dataframe 中的多个列并找到计数唯一值

[英]Iterate through multiple columns in a Panda dataframe and find count unique values

I am working with a dataset which looks like below:我正在使用如下所示的数据集:

在此处输入图像描述

I have imported this dataset to my code using the panda library.我已使用熊猫库将此数据集导入到我的代码中。 My goal is to find unique entries of the programming languages from columns 2, 3, 4. I wish the output to be:我的目标是从第 2、3、4 列中找到编程语言的唯一条目。我希望 output 是:

    Python 4
    Perl 3
    C++ 3
....

Any leads would be helpful任何线索都会有所帮助

Use DataFrame.filter with DataFrame.stack and Series.value_counts :DataFrame.filterDataFrame.stackSeries.value_counts一起使用:

s = df.filter(like='Language').stack().value_counts()

This is an alternative way这是另一种方法

df['lang1'].value_counts() + df['lang2'].value_counts() + df['lang3'].value_counts()

or要么

cols = ['lang1', 'lang2', 'lang2']
sum([df[col].value_counts() for col in cols])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM