I have a pandas dataframe and the following code:
import pandas as pd
import plotly.express as px
box = ['A','B','B','B','C','A','B','C','A','B']
value = [90,16,26,36,92,12,14,84,27,11]
sample_data = pd.DataFrame(list(zip(box,value)), columns =['Box', 'Value'])
fig = px.histogram(sample_data,
color="Box",
nbins=10,
barmode="group",
range_x=[0, 100],
)
fig.show()
I want to create a Histogram(stacked/grouped) in plotly
. And I want to display the percentage of total values per box falling into a certain bin. For example, if box A
contains 5
values in the bin 0-10
and a total of 20 values in A
, then the histogram for box A
should display 25%
, and so on.
Note: I donβt want the percentage based on total values falling into a certain bin for all boxes, rather I want to display percentage per box in a particular bin.
What changes do I need to make here?