I have a dataframe extracted from WhatsApp with columns: Date&Time, msg, name, msg_len.
Date&Time is a DateTime object that represents when the message has been sent, msg is the actual message, name is who sent the message and msg_len is the actual length of the message.
I'm trying to build a stacked bar plot using this dataframe: on the X-axis the date (e.g. 2019-02), on the y-axis, the mean length or the number of messages sent in that month and each bar is divided by each person. So far my function looks like this:
def BarPlotMonth(Data):
"""
This function plots a barplot for the number of messages sent for each month and the mean length of the messages for each month
"""
fig,axes = plt.subplots(2,1,
figsize=(18,10),
sharex = True)
GroupedByMonth = Data.groupby(Data['Date&Time'].dt.strftime('%Y-%m'))['msg_len']
Mean = GroupedByMonth.mean()
Count = GroupedByMonth.count()
Std = GroupedByMonth.std()
axes[0].bar(Count.index, Count, color = 'lightblue')
axes[0].set_title('Number of text per month')
axes[0].set_ylabel('Count')
axes[1].bar(Mean.index, Mean, color = 'lightblue', yerr = Std)
axes[1].set_title('Mean lenght of a message per month')
axes[1].set_ylabel('Mean lenght')
axes[1].set_xlabel('Year-Month')
plt.xticks(rotation=45)
axes[1].legend()
plt.savefig('WhatsApp_conversations.png')
plt.show()
But I can't divide each bar. How can I solve this?

axes.barfor each person if you want to separate by person.