How can I display the calculated mean of the total bill of Thursday and Friday versus the calculated mean of Saturday and Sunday in a stacked bar chart?
Thus, instead of 20 and 12 I want to display 17.15 and 17.68 and instead of 14 and 18 I want to display 20.44 and 21.41? Of course, I could just copy and paste the calculated values, but I prefer to take them directly from pandas.
In the next step, I would like to add error bars depicting the calculated sem for the respective days.
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv')
animals=['giraffes', 'orangutans']
# Group and calculate the mean and sem
mean = df.groupby('day').mean()
sem = df.groupby('day').sem()
fig = go.Figure(data=[
go.Bar(name='Mean of Thursday and Friday', x=animals, y=[20, 14]),
go.Bar(name='Mean of Saturday and Sunday', x=animals, y=[12, 18])
])
# Change the bar mode
fig.update_layout(barmode='stack')
fig.show()
print(mean)
print(sem)
Mean
total_bill tip size
day
Fri 17.151579 2.734737 2.105263
Sat 20.441379 2.993103 2.517241
Sun 21.410000 3.255132 2.842105
Thur 17.682742 2.771452 2.451613
SEM
total_bill tip size
day
Fri 1.904761 0.233907 0.130109
Sat 1.016408 0.174863 0.087835
Sun 1.013114 0.141650 0.115550
Thur 1.001545 0.157509 0.135418