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
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.