Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
900 views
in Technique[技术] by (71.8m points)

python - Seaborn: Plot a Barplot showing the Mean of an Attribute on the Y Axis?

I am new to Seaborn, and I am trying to plot a barplot that shows the average (mean) of an attribute on the Y axis, but I am unsure what is going wrong with my code.

This is my code:

fig, ax = plt.subplots(figsize=(15,10))
sns.barplot(data=df, x='Day', y=df['Spending'].mean())
ax.set(xlabel="Day of the Week", ylabel = "Average Spending each Day")

When I try to execute my code, I just get this error:

AttributeError: 'bool' object has no attribute 'all'

Any help on how to get the average to show on my Y axis would be greatly appreciated, including what I am doing wrong.

Thank you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

By default,

sns.barplot(data=df, x='Day', y='Spending')

shows the mean of Spending on the y axis.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...