- Upload the
books.csv
file - View tables and summary statistics
- See price analysis using NumPy
- Visualize ratings, categories, and prices using graphs
📊 Project: Book Data Explorer with Streamlit
🎯 Features
✅ Upload books.csv
✅ Show book data in table format
✅ Display price stats (NumPy)
✅ Category & rating analysis
✅ Interactive charts: bar plots, histograms
📦 Install Requirements
pip install streamlit pandas numpy matplotlib seaborn
📁 Folder Structure
book_streamlit_dashboard/
├── app.py
└── books.csv ← (optional default file to test)
📝 app.py
import streamlit as st
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
st.set_page_config(page_title="📚 Book Data Explorer", layout="wide")
st.title("📚 Book Data Explorer with Streamlit")
# ---- File Upload ----
uploaded_file = st.file_uploader("Upload your books.csv file", type=["csv"])
@st.cache_data
def load_data(file):
df = pd.read_csv(file)
# Clean price column (remove £ and convert to float)
df['price'] = df['price'].str.replace('£', '', regex=False).astype(float)
return df
if uploaded_file:
df = load_data(uploaded_file)
st.success("Data loaded successfully!")
# ---- Data Preview ----
st.subheader("🔍 Preview of Book Data")
st.dataframe(df.head(20), use_container_width=True)
# ---- NumPy Price Stats ----
st.subheader("📈 Price Statistics (NumPy)")
prices = df['price'].values
col1, col2, col3, col4 = st.columns(4)
col1.metric("Min Price", f"£{np.min(prices):.2f}")
col2.metric("Max Price", f"£{np.max(prices):.2f}")
col3.metric("Mean Price", f"£{np.mean(prices):.2f}")
col4.metric("Std Dev", f"£{np.std(prices):.2f}")
# ---- Ratings Distribution ----
st.subheader("⭐ Rating Distribution")
rating_counts = df['rating'].value_counts().sort_index()
st.bar_chart(rating_counts)
# ---- Price Distribution ----
st.subheader("📉 Price Distribution")
fig1, ax1 = plt.subplots()
sns.histplot(df['price'], kde=True, color='orange', ax=ax1)
ax1.set_xlabel("Price (£)")
ax1.set_title("Histogram of Book Prices")
st.pyplot(fig1)
# ---- Top N Expensive Books ----
st.subheader("💰 Top Expensive Books")
top_n = st.slider("Select number of top books", min_value=5, max_value=30, value=10)
top_books = df.sort_values(by='price', ascending=False).head(top_n)
st.dataframe(top_books[['title', 'price', 'rating']], use_container_width=True)
# ---- Search Books ----
st.subheader("🔎 Search Books by Title")
search_term = st.text_input("Enter title keyword:")
if search_term:
result = df[df['title'].str.contains(search_term, case=False, na=False)]
st.write(f"Found {len(result)} book(s):")
st.dataframe(result, use_container_width=True)
else:
st.info("Please upload a `books.csv` file to begin.")
🧪 To Run the App
streamlit run app.py
🖼️ What Students Will See
- Upload section
- Live data table
- Metric cards for prices
- Interactive bar charts (ratings, categories)
- Histogram of prices
- Search box for books
💡 Extension Ideas
- Filter by rating/category/price range
- Download filtered results
- Add pie chart of stock availability
- Add author analysis if included in dataset