AzureML / app.py
Ivanphi's picture
Upload folder using huggingface_hub
c35504e verified
Raw
History Blame Contribute Delete
2.32 kB
import streamlit as st
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
# Load data
def load_data():
df = pd.read_csv("processed_data.csv") # replace with your dataset
return df
# Create Streamlit app
def app():
# Title for the app
st.title("OLA Trip Data Analysis Dashboard")
df = load_data()
df = pd.DataFrame(df)
# Metrics
total_bookings = df['booking id'].nunique()
total_revenue = df['total_trip_cost'].sum()
average_trip_time = df['time_taken'].mean()
average_rating = df['ratings'].mean()
average_trip_cost = df['total_trip_cost'].mean()
# Display metrics on the sidebar
st.sidebar.header("Key Metrics")
st.sidebar.metric("Total Bookings", total_bookings)
st.sidebar.metric("Total Revenue", f"${total_revenue:.2f}")
st.sidebar.metric("Average Trip Cost", f"${average_trip_cost:.2f}")
st.sidebar.metric("Average Trip Time (min)", round(average_trip_time, 2))
st.sidebar.metric("Average Rating", round(average_rating, 2))
plots = [
{"title": "Rating by Category", "x": "category", "y": "ratings", "estimator": sum, "ci": None, "plot": sns.barplot},
{"title": "Purpose by Booking", "x": "reason", "plot": sns.countplot},
{"title": "Distance Travelled by Category", "x": "category", "y": "distance_travelled", "color": "lightblue", "plot": sns.barplot},
{"title": "Time Taken by Category", "x": "category", "y": "time_taken", "color": "lightgreen", "plot": sns.barplot},
{"title": "Total Bookings by Weekday", "data": df['weekday'].value_counts().sort_index(), "x": "index", "y": "values", "plot": sns.lineplot},
{"title": "Total Revenue by Month", "data": df.groupby('month')['total_trip_cost'].mean(), "x": "index", "y": "values", "plot": sns.lineplot}
]
for plot in plots:
st.subheader(plot["title"])
plt.figure(figsize=(10, 6))
if "data" in plot:
plot["plot"](x=plot["data"].index.astype(str), y=plot["data"].values)
else:
plot["plot"](data=df, x=plot["x"], y=plot.get("y"), estimator=plot.get("estimator"), ci=plot.get("ci"), color=plot.get("color"))
plt.title(plot["title"])
plt.xticks(rotation=45)
st.pyplot(plt)
if __name__ == "__main__":
app()