My pandas data frame has two columns: category and duration. And
I use the following code to make a box plot of all data points.
import matplotlib.pyplot as plt
plt.boxplot(df.duration)
plt.show()
However, if I want one box fore each category, how do I modify the above code? Thanks!
In addition to Wen's answer, which is spot on, you might want to check out the seaborn library. It was made to do this kind of plot.
Seaborn is a Python visualization library based on matplotlib. It provides a high-level interface for drawing attractive statistical graphics.
Check the documentation for boxplots
Draw a box plot to show distributions with respect to categories.
sns.boxplot(data=df, x='category', y='duration')

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With