| import streamlit as st |
| import seaborn as sns |
| import matplotlib.pyplot as plt |
| import pandas as pd |
|
|
| |
| def load_data(): |
| df = pd.read_csv("processed_data.csv") |
| return df |
|
|
| |
| def app(): |
| |
| st.title("OLA Trip Data Analysis Dashboard") |
| df = load_data() |
|
|
| df = pd.DataFrame(df) |
| |
| 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() |
| |
| |
| 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() |
|
|