Pandas-Python中的子批处理多个列

2024-09-29 06:29:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Python新手,正在努力有效地解决这个问题。我读了很多例子,但它们都很复杂,缺乏理解力。对于下面的数据帧,我喜欢对每列进行子划分,而忽略前两个即站点标识和单元格标识:

  • 可用性
  • 沃尔特CSSR
  • 伏尔泰尝试

每个子批次(可用性等)将包括“分组”站点标识作为图例。每个子批次都保存到所需的位置。在

样本数据:

Date   Site_ID  Cell_ID   Availability  VoLTE CSSR   VoLTE Attempts
22/03/2019  23181   23181B11    100      99.546435  264
03/03/2019  91219   91219A11    100      99.973934  663
17/04/2019  61212   61212A80    100      99.898843  1289
29/04/2019  91219   91219B26    99.907407   100 147
24/03/2019  61212   61212A11    100      99.831425  812
25/04/2019  61212   61212B11    100      99.91107   2677
29/03/2019  91219   91219A26    100      99.980066  1087
05/04/2019  91705   91705C11    100      99.331263  1090
04/04/2019  91219   91219A26    100      99.984588  914
19/03/2019  61212   61212B11    94.21875    99.934376   2318
23/03/2019  23182   23182B11    100      99.47367   195
02/04/2019  91219   91219A26    100      99.980123  958
26/03/2019  23181   23181A11    100      99.48185   543
19/03/2019  61212   61212A11    94.21875    99.777605   1596
18/04/2019  23182   23182B11    100      99.978012  264
26/03/2019  23181   23181C11    100      99.829911  1347
01/03/2019  91219   91219A11    100      99.770661  1499
12/03/2019  91219   91219B11    100      99.832273  1397
19/04/2019  61212   61212B80    100      99.987946  430
12/03/2019  91705   91705C11    100      98.789819  1000

这是我效率低下的解决方案,考虑到有100多个专栏,我很担心。在

^{pr2}$

这就是我追求的结果。 End Result


Tags: 数据iddate站点sitecell标识例子
1条回答
网友
1楼 · 发布于 2024-09-29 06:29:29

不是最佳解决方案,但您可以尝试:

fig, axes = plt.subplots(1,3, figsize=(10,4))

for col, ax in zip(cols, axes):
    for site in df.Site_ID.unique():
        tmp_df = df[df.Site_ID.eq(site)]
        ax.plot(tmp_df.Date, tmp_df[col], label=site)

    ax.set_title(col) 
    ax.legend()

plt.show()

输出:

enter image description here

相关问题 更多 >