Skip to content

Instantly share code, notes, and snippets.

@pmbaumgartner
Created December 20, 2019 14:11
Show Gist options
  • Save pmbaumgartner/4558781c0dfe8a4539201eaeb575ba51 to your computer and use it in GitHub Desktop.
Save pmbaumgartner/4558781c0dfe8a4539201eaeb575ba51 to your computer and use it in GitHub Desktop.
How to use `format_func` with a streamlit widget and a dictionary
import streamlit as st
from vega_datasets import data
@st.cache
def load_data():
return data.birdstrikes()
cols = {
"Airport__Name": "Airport Name",
"Aircraft__Make_Model": "Aircraft Make & Model",
"Effect__Amount_of_damage": "Effect: Amount of Damage",
"Flight_Date": "Flight Date",
"Aircraft__Airline_Operator": "Airline Operator",
"Origin_State": "Origin State",
"When__Phase_of_flight": "When (Phase of Flight)",
"Wildlife__Size": "Wildlife Size",
"Wildlife__Species": "Wildlife Species",
"When__Time_of_day": "When (Time of Day)",
"Cost__Other": "Cost (Other)",
"Cost__Repair": "Cost (Repair)",
"Cost__Total_$": "Cost (Total) ($)",
"Speed_IAS_in_knots": "Speed (in Knots)",
}
dataset = load_data()
column = st.selectbox("Describe Column", list(dataset.columns), format_func=cols.get)
st.write(dataset[column].describe())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment