pandas将数据帧绘制为多个条形图

jxn*_*jxn 4 python plot matplotlib pandas

这是我的熊猫数据帧df:

          ab             channel   booked
0    control             book_it     466
1    control          contact_me     536
2    control             instant     17
3  treatment             book_it     494
4  treatment          contact_me     56
5  treatment             instant     22
Run Code Online (Sandbox Code Playgroud)

我想绘制3组条形图(根据channel):

对于每个渠道:绘制控制预订值与处理预订值.

因此我应该得到6个条形图,分为3组,每组有控制和治疗预定值.

到目前为止,我只能预订,但没有按ab分组:

ax = df_conv['booked'].plot(kind='bar',figsize=(15,10), fontsize=12)
ax.set_xlabel('dim_contact_channel',fontsize=12)
ax.set_ylabel('channel',fontsize=12)
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

这就是我想要的(只显示4但这是要点): 在此输入图像描述

Sto*_*ica 15

旋转数据框,使控制和处理值位于不同的列中.

df.pivot(index='channel', columns='ab', values='booked').plot(kind='bar')
Run Code Online (Sandbox Code Playgroud)

酒吧情节