How to use one column of datarame as filter in select box and show rest columns as bar chart


I am new to Streamlit. I have a dataframe which I want to visualize as bar chart. The first column of DF will be the part of select box. The column names (except 1st column) should be the x-axis and the values will be y-axis. The values will change depending upon the filter selected. Will appreciate guidance here.


Here is a sample code.

import streamlit as st
import pandas as pd
import as px

# Sample data in dict for dataframe.
data = {
    'country': ['aaa', 'bbb', 'cccc'],
    'airports': [12, 2, 42],
    'population': [1200, 105, 7500]

# Build df.
df = pd.DataFrame(data)
st.dataframe(df, use_container_width=True)

sel_country = st.selectbox('**Select country**',
fil_df = df[ == sel_country]  # filter

# Build a new df based from filter.
new_df = pd.melt(fil_df, id_vars=['country'], var_name="feature",
                 value_vars=['airports', 'population'])

logy = True  # to make small values visible
textauto = True  # to write plot label
title = f'country name: {sel_country}'
fig =, x='feature', y='value',
             height=300, log_y=logy, text_auto=textauto,

with st.expander('**Country Info**', expanded=True):
    st.plotly_chart(fig, use_container_width=True)