2

Grouping data by date:

grouped = tickets.groupby(['date'])
size = grouped.size()
size

and then plot it using:

size.plot(kind='bar')

Result: enter image description here

However,I need to group data by date and then subgroup on modeofcommunication, and then finally plot the count of each subgroup.

grouped = df.groupby([‘date’,’modeofcommunication'])
size = grouped.size()
size

Result looks like:

date                modeofcommunication
2019-03-15          Chat                       2
                    Internal Email             2
                    Phone                      4

2019-03-16          Chat                      25
                    Email                     20
                    Feedback Form              2
                    Phone                      6

2019-03-17          Chat                      23
                    Email                     68
                    Feedback Form             13
                    Internal Email             3


2019-03-18          Chat                    1822
                    Email                     57
                    Facebook                  14
                    Feedback Form             11
                    Internal Email            11
                    Phone                    812
                    Twitter                    4

How can I plot a bar graph for the grouped data such that the count of each subgroup(mode of communication) is represented as a vertical bar under the parent group?

1 Answer 1

1

I believe you need Series.unstack for DataFrame from MultiIndex Seriesand then DataFrame.plot.bar:

size.unstack().plot.bar()

Or:

size.unstack().plot.bar(stacked=True)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @jezraeil. Both the solutions work very well, exactly what I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.