How to create a bar showing the level of the value?

Hello everyone!! I’m trying to creat a char showing the level of the value but I don’t know how to do it. Please help me to solve my problem. The barchart I want to show like this.
When I choose the movie, the bar chart will show the level of each geners like picture
Screenshot 2022-11-19 161531

Here is an idea :dotted_line_face:

Code
import streamlit as st
import pandas as pd 

def ascii_progress(x: float, solid: bool = False) -> str:
    '''
    Returns an ascii bar from a number between 0 and 1. 
    The bar has lenght 10
    '''
    nbars = int(min(max(x, 0.0), min(x, 1.0), x) * 10)
    bar = ((("\u2593","\u2588")[solid])*nbars).ljust(10,"\u2591")
    return(bar)

df = pd.DataFrame({"thing":["Python", "C++", "JS"], "x": [0.2, 0.6, 0.9]})
df["bar"] = df["x"].map(ascii_progress)
st.dataframe(df)

dataframe

Or using a little image in markdown

Code
import streamlit as st
import pandas as pd 

def markdown_progress(x: float) -> str:
    '''
    Returns a bar from a number between 0 and 100. 
    '''
    return(f"""![](https://geps.dev/progress/{x})""")

df = pd.DataFrame({"thing":["Python", "C++", "JS"], "x": [20, 50, 90]})
df["bar"] = df["x"].map(markdown_progress)
st.markdown(df.to_markdown())

image

5 Likes

Thank you @edsaac. I’m very impressed with your solution.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.