1

This is the plot i have right now.

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

test

    id     score  type
0   1  0.191519     0
1   1  0.622109     1
2   2  0.437728     0
3   2  0.785359     1
4   3  0.779976     0
5   3  0.272593     1
6   4  0.276464     0
7   4  0.801872     1

test.plot(x='id',y='score',kind='bar')

enter image description here

How do I plot it so it groups it by the 'type' column and a different color for each type? For example 'type' 1, i want the bars to be next to each other and color red for 'type 1 and color blue for 'type 0' so it's easier for comparison.

1 Answer 1

2

Assuming you want to sum your groupings, would this work? If not, you can probably play around with it to achieve your objectives. If not, please post a table of the summary result that you'd like to graph.

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

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.