简体   繁体   English

如何在pydatadable中使用group by计算每个类别的实例数

[英]How to count the number of instances for each category using group by in pydatadable

I have a dataframe as showed below, and here i wanted to apply group by and count operations on it get the count of each category in a pydatatable way?.我有一个 dataframe 如下所示,在这里我想应用分组并对其进行计数操作以 pydatatable 方式获取每个类别的计数?

here is a sample dt contains the different programming languages这是一个示例 dt 包含不同的编程语言

prog_lang_dt = dt.Frame({"languages": ['html','R','R','html','R','javascript','R','javascript','html']})

Here is a code that i'm trying to apply group and count operations这是我正在尝试应用组和计数操作的代码

prog_lang_dt[:,:,by(f.languages)]

Is there any count specific function for it in place of J... DT[i,j,by]是否有任何计数特定的 function 代替 J... DT[i,j,by]

The count() method can be used to find the number of elements in each group: count()方法可用于查找每个组中的元素数:

from datatable import dt, f, by, count

prog_lang_dt = dt.Frame(languages= ['html', 'R', 'R', 'html', 'R', 'javascript',
                                    'R', 'javascript', 'html'])
prog_lang_dt[:, count(), by(f.languages)]

produces生产

   | languages   count
-- + ----------  -----
 0 | R               4
 1 | html            3
 2 | javascript      2

[3 rows x 2 columns]

Although not needed for your example, but the function count can also take a column as an argument, in which case it will report the number of non-missing entries in that specific column.尽管您的示例不需要,但 function count也可以将列作为参数,在这种情况下,它将报告该特定列中非缺失条目的数量。

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

相关问题 如何计算每个组的条目数? - How to count the number of entries belonging to each group? 我将如何计算每个类别 BMI 计算器中的人数 - How would I count the number of people in each category BMI calculator 如何在条形图上为每个类别添加观察计数? 使用Matplotlib - How to add a count of observations for each category on a barplot? Using Matplotlib 如何按类别分组,然后使用 Pandas 统计词的频率 - How to group by category and then count the frequency of words using Pandas 如何计算每组的某些课程的重复次数 - How to count the number of repetition for certain class for each group 在 Pandas DataFrames 中使用 count.values 和/或 sort.values 按每个给定类别对值的数量进行排序 - Using count.values and/or sort.values in Pandas DataFrames to sort number of values by each given category 在 Python 中使用元类计​​算实例数 - Count number of instances using a metaclass in Python 计算每个组中重复项的数量 - Count number of duplicates within each group 计算每个组内的元素数 - Count the number of element within each group 您如何创建一个 function 来接收类别列表并计算每个类别中的元素数量? - How do you create a function that would take in a list of categories and count the number of elements in each category?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM