0

I have a dataframe like

key, value_1, counts

1, "foo", 20
1, "bar", 45
1, "baz", 22
5, "bar", 24
2, "foo", 15

and so on..

Now, I want to plot multiple(bar) plots corresponding for each key based on counts of each value_1

So plot 1 is like bar plot of 45,22, 20 (sorted(["foo", "bar", "baz"]) values)

My noob way is to slice the dataframe by index and then plot it. But I was wondering if there is a more pythonic way to do this?

3
  • A separate figure for each unique value of 'key'? Commented Jan 15, 2019 at 18:39
  • It would help to see an example plot, or the code for your "noob way" to understand what you're asking Commented Jan 15, 2019 at 18:43
  • What do you think is not pythonic enough in your code? Commented Jan 15, 2019 at 18:53

1 Answer 1

2

You can use groupby and plot

for name, grp in df.groupby('key'):
    grp.plot.bar('value_1', 'counts', title = name)
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.