i have df.
df
I want add in my visualization ‘Sub-Category’ in x axes.
How i can do that?
Code:
df_neg_val.plot(kind='bar',x = 'Year',y='Profit')
If i pointing two args in x = ” – i have error.
I’m read documentation, but i’m bad know english 🙁
Thanks for you reply 🙂
>Solution :
You could .pivot() your DataFrame so that Year becomes the index and SubCategory the columns, then plot it.
df = pd.DataFrame({
"Year": [2000, 2000, 2001, 2001, 2002, 2002],
"Pet": ["Dog", "Cat", "Dog", "Cat", "Dog", "Cat"],
"Weight": [10, 5, 11, 6, 10, 6]})
df.pivot(index="Year", columns="Pet", values="Weight").plot.bar()
As an aside, I don’t love bar plots with years along the x-axis, as I don’t consider years to be a categorical variable.
