I have a pandas dataframe which looks like this:
I want to plot graphs using this dataframe. The plot will have country names on
X-axis and the
mean/sum of the sold of each country will on
y-axis . I know I can compute the mean/sum using the group by function like this:
I know the plotly histogram has the function that can directly compute the value and plot the graph. But I want to apply on other graph of
plotly such as
bar chart to make the graph more interactive. I am having a hard time figuring it out. Can anyone please help me out?
Hi @Yuechean, if you want to plot the sum you can do it with plotly express:
import plotly.express as px
import pandas as pd
df = pd.DataFrame()
df['country'] = ['India', 'India', 'Japan', 'Japan', 'China']
df['sold'] = [5, 3, 7, 2, 6]
fig = px.bar(df, x='country', y='sold')
px.bar will add one bar marker for each line, so that the different lines for a given
country will add up.
Hi @Emmanuelle, I also want to plot the mean, variance or standard deviation. Is there any way to do it?
Hi @Yuechean , this can be used for plotting two grouped line charts.
You can also use line+bar combination or bar+bar or any other.
#This will plot Line for Sum and Bar for Mean in the same plot
You can use add trace for other groupings as well like variance,mean,standard deviation etc on the same plot.