使用 groupby 方法
df = Al[['Connection Name','UAS-RS', 'SES-RS', 'OFS-RS', 'ES-RS', 'BBE-RS', 'Date', 'Alarm Type']]
cols = ['Connection Name', 'Date', 'Alarm Type']
df.mask(df == 0, np.nan).groupby(cols)[['UAS-RS', 'SES-RS', 'OFS-RS', 'ES-RS', 'BBE-RS']].count()
我得到了下表:

初始表具有以下结构之王:
| ConName | Date | Alarm | ETH1 | ETH2 | ETH 3|
| AR21 | 25-01-19 | AL1 | 1 | 0 | 3 |
| AR22 | 25-01-19 | AL2 | 0 | 0 | 1 |
| AR23 | 26-01-19 | AL1 | 1 | 1 | 0 |
| AR21 | 26-01-19 | AL2 | 0 | 1 | 0 |
问题
我想为每个连接名称构建条形图,描述两种警报类型之间的特征分布。
我得到什么:

所需的输出:

我最后一个只为一个连接名称构建绘图的代码:
for date in df[df['Connection Name']=='AR-CY18 A2.5G-RTA33']['Date']:
df.mask(df == 0, np.nan).groupby('Alarm Type')[['UAS-RS', 'SES-RS', 'OFS-RS', 'ES-RS', 'BBE-RS']].count().plot(kind='bar',stacked=True,subplots=True)
另外,问题是,该脚本按日期构建了多个绘图(我在第 77 个绘图上中断了内核),并具有相同的输出。
我究竟做错了什么?unstacking (unstack().plot.barh()) 也没有帮助。
欢迎提供任何线索。
