How to make graphics in pandas

Here is what I have right now:

np.random.seed(1234)
test = pd.DataFrame({'week': [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2],
                     'score': np.random.uniform(0, 1, 12),
                     'type': [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
                     'type2': [3, 3, 4, 4, 5, 5, 3, 3, 4, 4, 5, 5]})

test.groupby(['week', 'type', 'type2']).agg('sum').unstack().plot(kind='bar')

enter image description here

How do I build a facet based on type? I want two different graphs: one for type = 1 and the other type = 2.

+4
source share
1 answer

You need to unfasten so that typeare the columns, and then use the parameter subplots:

test.groupby(['week', 'type', 
              'type2']).agg('sum').unstack(1).plot(kind='bar', subplots=True)

Resulting plot

enter image description here

+3
source

Source: https://habr.com/ru/post/1583902/


All Articles