I have scraped all the scores of products in different areas. Now I would like to make comparison of these scores in different areas with selected products. I was thinking of using bar charts (due to lack of imagination and try to do it as simple as possible first).
However, I can’t understand how I select different rows (where the scores are) from the excel file and display this in a bar chart. Would like to know if someone give me some advice
In Python, the preferred way to manipulate data is using the Pandas library.
there is a function for reading an Excel file into a Pandas dataframe. This article may also help you load the data and install some optional dependencies. So for example df = pd.read_excel("path/to/file.xlsx").
When your Excel data is in a DataFrame, you will look on how to filter rows depending on a product. There are guides for this in the documentation, here’s one from the 10 minute quickstart. The query would look like df_selected_by_column = df[df['product'] =="your_product"]
Finally if you are looking for the simple bar chart you can try Streamlit’s builtin bar_chart, you may need to filter your columns a bit beforehand, like st.bar_chart(df_selected_by_column[["product", "value"]).
If you want users to give you a bit more specific advice, you could provide us with part of the Excel file and a chart example you would want to display .
import streamlit as st
import pandas as pd
import plotly.express as px
# continue loading the data with your excel file, I was a bit too lazy to build an Excel file :)
df = pd.DataFrame(
[["Product A", 5.6, 7.8, 5], ["Product B", 5.8, 7.2, 4.9]],
columns=["Product", "Comfort", "Sound", "Calls"]
)
fig = px.bar(df, x="Product", y=["Comfort", "Sound", "Calls"], barmode='group', height=400)
# st.dataframe(df) # if need to display dataframe
st.plotly_chart(fig)
Afterwards it becomes more of a reading the graph library documentation (notably because I guess you’d prefer to group by score rather than product?) though rather than a Streamlit question…but feel free to edit the code and see the graph result in Streamlit in realtime to better understand what happens when you edit things!
There’s a labels argument in the plotly_express call you can use to edit x/y axis labels, something like px.bar(df=df, x=x, y=y, labels={"variable": "Product count"}) for example.
You also have fig.update_yaxes which I think let’s you edit the text of the title if you find the correct argument:
fig.update_yaxes(
title_text="Product Count"
)
Hope you can find it out, let us know if you need a bit more detail