To build a data dashboard with Python you need one library and one file. Streamlit turns a short pandas script into an interactive web page with filters, headline numbers and charts, and you do not write any HTML or JavaScript. In this tutorial we build a complete dashboard on real data, run it, test it and then put it online.
The data is the Consumer Complaint Database from the US Consumer Financial Protection Bureau (CFPB): complaints about mortgages, debt collectors, credit reports and other financial products. We use a 65,499-row snapshot of it, and the finished dashboard is about 60 lines of code. Every number in this article comes from running that code.
What you will build: a data dashboard
The dashboard has a sidebar with two filters (product and date range), three headline numbers, two charts of complaint volume, a chart of late responses, and a table of the companies with the most complaints. Change a filter and everything updates. The chart below shows the numbers behind the dashboard’s late-response chart, which we build in Step 5.

Step 1: Install the tools
You need a recent Python 3 (we used 3.13). Create a virtual environment and install two packages:
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install streamlit pandasThis article was tested with Streamlit 1.67.0 and pandas 3.0.5 on Python 3.13. If you have never used pandas, our pandas tutorial covers the basics we use here.
Step 2: Load the data once
Streamlit re-runs your whole script every time someone touches a widget. If the script downloads a 15 MB file each time, the dashboard feels broken. The @st.cache_data decorator fixes this: the function runs once and Streamlit remembers the result.
import pandas as pd
import streamlit as st
URL = ("https://raw.githubusercontent.com/saklain23/"
"customer-complaint-sql-analysis/main/Consumer_Complaints.csv")
COLS = ["Date Received", "Product Name", "Company", "State Name",
"Submitted via", "Timely Response", "Consumer Disputed"]
st.set_page_config(page_title="CFPB complaints dashboard", layout="wide")
@st.cache_data
def load(path: str = URL) -> pd.DataFrame:
df = pd.read_csv(path, usecols=COLS, parse_dates=["Date Received"])
# keep complete months only (Aug 2013 to Apr 2015)
df = df[df["Date Received"].between("2013-08-01", "2015-04-30")].copy()
df["Timely"] = df["Timely Response"].eq("Yes")
df["Disputed"] = df["Consumer Disputed"].map({"Yes": 1.0, "No": 0.0})
return df
df = load()Two cleaning choices matter. First, the file has 65,499 complaints, but July 2013 and the months after April 2015 are only partly covered (809 complaints in July 2013, and a thin tail of 1,706 after April 2015). Left in, they would show up as fake cliffs on the monthly chart, so we keep the 62,984 complaints from the 21 complete months. Second, Consumer Disputed is empty for some rows, so we turn Yes and No into 1.0 and 0.0 and let the blanks stay missing. A mean of that column then ignores them.
Step 3: Add filters in the sidebar
st.title("Consumer complaints dashboard")
st.caption("CFPB Consumer Complaint Database, complete months "
"August 2013 to April 2015")
# Sidebar filters
products = sorted(df["Product Name"].unique())
chosen = st.sidebar.multiselect("Product", products, default=products)
first, last = df["Date Received"].min().date(), df["Date Received"].max().date()
picked = st.sidebar.date_input("Dates received", (first, last),
min_value=first, max_value=last)
if len(picked) != 2: # the user has clicked only the first date so far
st.info("Pick an end date to update the dashboard.")
st.stop()
start, end = picked
view = df[df["Product Name"].isin(chosen)
& df["Date Received"].between(pd.Timestamp(start), pd.Timestamp(end))]
if view.empty:
st.warning("No complaints match these filters.")
st.stop()Everything below this point reads from view, the filtered copy, never from df. That is the one rule that keeps a dashboard consistent. The st.stop() guard matters too: if a visitor clears the product list, every average below would fail on an empty table, so we show a message and stop instead.
Step 4: Show headline numbers
a, b, c = st.columns(3)
a.metric("Complaints", f"{len(view):,}")
b.metric("Answered on time", f"{view['Timely'].mean():.1%}")
c.metric("Consumer disputed", f"{view['Disputed'].mean():.1%}")With no filters applied the dashboard shows 62,984 complaints, 97.7% answered on time and 20.3% disputed by the consumer. Those three numbers are what most readers look at first, so they go at the top.
Step 5: Add charts
left, right = st.columns(2)
with left:
st.subheader("Complaints per month")
monthly = view.set_index("Date Received").resample("MS").size()
st.line_chart(monthly)
with right:
st.subheader("Complaints by product")
st.bar_chart(view["Product Name"].value_counts())
st.subheader("Share answered late, by product (%)")
late = (1 - view.groupby("Product Name")["Timely"].mean()) * 100
st.bar_chart(late.sort_values(ascending=False))resample("MS") groups complaints by month start, so the line chart gets one point per month. The last chart shows the share answered late instead of on time on purpose. When 97.7% of complaints are on time, a bar chart of on-time rates is a row of equally tall bars. Flipping it to late responses makes the small differences visible.
Step 6: Add a table of companies
top = (view.groupby("Company")
.agg(complaints=("Timely", "size"), on_time=("Timely", "mean"))
.nlargest(10, "complaints"))
top["on_time"] = (top["on_time"] * 100).round(1)
st.dataframe(top.rename(columns={"on_time": "on time (%)"}))Step 7: Run it
Save everything above as app.py (the complete file is in the last section) and start the server:
streamlit run app.pyStreamlit opens http://localhost:8501. Edit the file, save, and the page offers to re-run; there is no build step.
What the dashboard shows
Once it runs, the data answers questions that a spreadsheet would hide:
- Mortgages and debt collection dominate. Mortgage has 17,964 complaints (29% of the total), debt collection 15,598 and credit reporting 11,651. Those three products account for 72% of everything.
- Volume grew. The first five complete months average 2,380 complaints a month, the last five 3,216. March 2015 is the peak at 3,617.
- Late responses are rare but uneven. Overall 1,436 of 62,984 complaints (2.3%) were answered late. Payday loans are the worst at 8.7% late and debt collection is next at 5.7%, while credit reporting is at 0.1%.
- The biggest names are banks and credit bureaus. Bank of America has 4,497 complaints, Experian 4,065 and Equifax 4,024.
Filtering to Payday loan alone, the headline numbers become 621 complaints, 91.3% on time and 17.1% disputed. That is a small product with the worst on-time record, which is exactly the kind of pattern a dashboard is for. Debt collection stands out as well: it is the second-largest category and second worst on time.
One caution: this is a snapshot of the database, not all of it, and “late” means the CFPB recorded a company response as not timely. Complaint counts also say nothing about company size, so a large bank with many customers will naturally have more complaints.
Test the app without a browser
You can check that a dashboard works without opening it. Streamlit ships a test runner, AppTest, that runs the script and lets you set widgets from code:
from streamlit.testing.v1 import AppTest
at = AppTest.from_file("app.py", default_timeout=120).run()
assert not at.exception, at.exception
print([m.value for m in at.metric]) # ['62,984', '97.7%', '20.3%']
at.sidebar.multiselect[0].set_value(["Payday loan"]).run()
print([m.value for m in at.metric]) # ['621', '91.3%', '17.1%']
at.sidebar.multiselect[0].set_value([]).run()
print(at.warning[0].value) # No complaints match these filters.The three outputs in the comments are what this test printed when we ran it. The last case is the empty-filter guard from Step 3. Put the test in a test_app.py file and run it with pytest or in your CI pipeline, as covered in our GitHub for data science guide.
Share it online
Streamlit Community Cloud hosts public apps for free. Push app.py and a requirements.txt (two lines: streamlit and pandas) to a GitHub repository, sign in at share.streamlit.io, choose the repository and the file, and deploy. Anyone with the link can use the dashboard. If you need a custom API behind your app instead of a dashboard, see how to deploy a model with Flask.
Common problems
- The app is slow after every click. Move the download and cleaning into a function with
@st.cache_data, as in Step 2. KeyErroron a column name. Column names differ between copies of this dataset. Printdf.columnsand match them exactly, including capital letters.- Charts show a cliff at the end. Partial months look like a collapse. Cut the data to complete months, as we did.
- The date picker raises a ValueError. With a date range,
st.date_inputreturns a single date until the visitor clicks the second one. That is why the script checkslen(picked)before unpacking.
The complete app.py
import pandas as pd
import streamlit as st
URL = ("https://raw.githubusercontent.com/saklain23/"
"customer-complaint-sql-analysis/main/Consumer_Complaints.csv")
COLS = ["Date Received", "Product Name", "Company", "State Name",
"Submitted via", "Timely Response", "Consumer Disputed"]
st.set_page_config(page_title="CFPB complaints dashboard", layout="wide")
@st.cache_data
def load(path: str = URL) -> pd.DataFrame:
df = pd.read_csv(path, usecols=COLS, parse_dates=["Date Received"])
# keep complete months only (Aug 2013 to Apr 2015)
df = df[df["Date Received"].between("2013-08-01", "2015-04-30")].copy()
df["Timely"] = df["Timely Response"].eq("Yes")
df["Disputed"] = df["Consumer Disputed"].map({"Yes": 1.0, "No": 0.0})
return df
df = load()
st.title("Consumer complaints dashboard")
st.caption("CFPB Consumer Complaint Database, complete months "
"August 2013 to April 2015")
# Sidebar filters
products = sorted(df["Product Name"].unique())
chosen = st.sidebar.multiselect("Product", products, default=products)
first, last = df["Date Received"].min().date(), df["Date Received"].max().date()
picked = st.sidebar.date_input("Dates received", (first, last),
min_value=first, max_value=last)
if len(picked) != 2: # the user has clicked only the first date so far
st.info("Pick an end date to update the dashboard.")
st.stop()
start, end = picked
view = df[df["Product Name"].isin(chosen)
& df["Date Received"].between(pd.Timestamp(start), pd.Timestamp(end))]
if view.empty:
st.warning("No complaints match these filters.")
st.stop()
# KPI row
a, b, c = st.columns(3)
a.metric("Complaints", f"{len(view):,}")
b.metric("Answered on time", f"{view['Timely'].mean():.1%}")
c.metric("Consumer disputed", f"{view['Disputed'].mean():.1%}")
# Charts
left, right = st.columns(2)
with left:
st.subheader("Complaints per month")
monthly = view.set_index("Date Received").resample("MS").size()
st.line_chart(monthly)
with right:
st.subheader("Complaints by product")
st.bar_chart(view["Product Name"].value_counts())
st.subheader("Share answered late, by product (%)")
late = (1 - view.groupby("Product Name")["Timely"].mean()) * 100
st.bar_chart(late.sort_values(ascending=False))
st.subheader("Companies with the most complaints")
top = (view.groupby("Company")
.agg(complaints=("Timely", "size"), on_time=("Timely", "mean"))
.nlargest(10, "complaints"))
top["on_time"] = (top["on_time"] * 100).round(1)
st.dataframe(top.rename(columns={"on_time": "on time (%)"}))For more chart types, see our Matplotlib guide; Streamlit also accepts Matplotlib, Plotly and Altair figures through st.pyplot, st.plotly_chart and st.altair_chart.
Frequently asked questions
How do I build a data dashboard in Python?
Install Streamlit and pandas, load your data in a cached function, add widgets in the sidebar to filter it, then draw metrics and charts from the filtered table. Run it with streamlit run app.py.
Do I need to know HTML or JavaScript?
No. Streamlit builds the page from your Python calls. You only need pandas for the data work.
Is Streamlit free?
Streamlit is open source and free to run on your own machine. Streamlit Community Cloud offers free hosting for public apps.
What is the difference between Streamlit, Dash and Power BI?
Streamlit and Dash are Python libraries, so a developer writes the dashboard as code. Power BI is a point-and-click business tool. Streamlit has the shortest path from a script to a page; Dash gives more control over layout.
Can I use my own data?
Yes. Replace the load() function so it reads your CSV, Excel file or database, and change the column names in the rest of the script. Our CSV to JSON tool is handy for checking what your data looks like first.
