Add percentage column and use plotly
Browse files
apps/parameters_distribution.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import pandas as pd
|
|
|
2 |
import streamlit as st
|
3 |
from pyxlsb import open_workbook
|
4 |
|
@@ -35,9 +36,21 @@ if uploaded_file:
|
|
35 |
with col1:
|
36 |
dist = df[param].value_counts(dropna=False).reset_index()
|
37 |
dist.columns = [param, "Count"]
|
|
|
|
|
|
|
38 |
st.dataframe(dist, use_container_width=True)
|
39 |
|
40 |
# Bar chart
|
41 |
with col2:
|
42 |
chart_data = dist.set_index(param)
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import pandas as pd
|
2 |
+
import plotly.express as px
|
3 |
import streamlit as st
|
4 |
from pyxlsb import open_workbook
|
5 |
|
|
|
36 |
with col1:
|
37 |
dist = df[param].value_counts(dropna=False).reset_index()
|
38 |
dist.columns = [param, "Count"]
|
39 |
+
dist["Percentage"] = (
|
40 |
+
dist["Count"] / dist["Count"].sum() * 100
|
41 |
+
).apply(lambda x: f"{x:.2f}%")
|
42 |
st.dataframe(dist, use_container_width=True)
|
43 |
|
44 |
# Bar chart
|
45 |
with col2:
|
46 |
chart_data = dist.set_index(param)
|
47 |
+
fig = px.bar(
|
48 |
+
chart_data.reset_index(),
|
49 |
+
x=param,
|
50 |
+
y="Count",
|
51 |
+
text_auto=True,
|
52 |
+
title=f"{param} Distribution",
|
53 |
+
hover_data=["Count", "Percentage"],
|
54 |
+
)
|
55 |
+
fig.update_xaxes(type="category")
|
56 |
+
st.plotly_chart(fig)
|