簡體   English   中英

如何計算每組的某些課程的重復次數

[英]How to count the number of repetition for certain class for each group

每個資產ID都有兩種類型的問題(“RSL嚴重偏差”或“RSL和TX功率偏差”),我們需要計算同一資產ID中每個問題的重復次數

Asset    ID    Categorization Tier 3
4053     0001  RSL Critical Deviation
4054     0001  RSL and TX Power Deviation
3342     0005  RSL and TX Power Deviation
3343     0005  RSL and TX Power Deviation
3344     0005  RSL and TX Power Deviation
3345     0005  RSL and TX Power Deviation
3346     0005  RSL and TX Power Deviation
4363     0040  RSL and TX Power Deviation
4055     0046  RSL Critical Deviation
4056     0046  RSL Critical Deviation

結果應該是

Asset ID  Categorization Tier 3     Count 
0001      RSL Critical Deviation        1
          RSL and TX Power Deviation    1
0005      RSL Critical Deviation        0
          RSL and TX Power Deviation    5
df.groupby(['ID', 'Categorization']).size()

SQL中的groupby語句可以應用於多個列。 熊貓也有這樣的舉動。 Pandas實現SQL的COUNT聚合的方法是使用sizecount 這個問題上回答了他們的不同之處。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM