├── README.md ├── ums python.txt └── ums python2.txt /README.md: -------------------------------------------------------------------------------- 1 | # EV-python-project 2 | Just completed an EDA project on electric vehicles using Python! 📊 Explored trends, cleaned real-world data, and visualized key insights. 3 | # 1. Importing Required Libraries 4 | import numpy as np 5 | import pandas as pd 6 | import matplotlib.pyplot as plt 7 | import seaborn as sns 8 | 9 | # Display settings 10 | plt.style.use('seaborn-v0_8') # Using the correct style name 11 | sns.set_style("whitegrid") 12 | plt.rcParams['figure.figsize'] = [12, 8] 13 | plt.rcParams['font.size'] = 12 14 | plt.rcParams['axes.labelsize'] = 14 15 | plt.rcParams['axes.titlesize'] = 16 16 | plt.rcParams['xtick.labelsize'] = 12 17 | plt.rcParams['ytick.labelsize'] = 12 18 | plt.rcParams['axes.grid'] = True 19 | plt.rcParams['grid.alpha'] = 0.3 20 | plt.rcParams['figure.dpi'] = 100 21 | 22 | # Custom color palette 23 | custom_palette = sns.color_palette("husl", 8) 24 | 25 | # 2. Loading the Dataset 26 | df = pd.read_csv("project.csv") 27 | 28 | # 3. Data Cleaning 29 | df.dropna(inplace=True) 30 | df.drop(columns=["State"], inplace=True) 31 | df.drop_duplicates(inplace=True) 32 | 33 | # 4. EV Growth Over Time 34 | ev_growth = df.groupby("Model Year").size().reset_index(name="Number of EVs") 35 | plt.figure(figsize=(14, 7)) 36 | sns.lineplot(data=ev_growth, x="Model Year", y="Number of EVs", 37 | marker="o", linewidth=2.5, color=custom_palette[0]) 38 | plt.title("Growth of Electric Vehicles Over Time", fontsize=18, pad=20) 39 | plt.xlabel("Model Year", fontsize=14) 40 | plt.ylabel("Number of EVs Registered", fontsize=14) 41 | plt.xticks(rotation=45) 42 | plt.grid(True, alpha=0.3) 43 | plt.tight_layout() 44 | plt.show() 45 | 46 | # 5. Top 10 EV Manufacturers 47 | top_makes = df['Make'].value_counts().head(10) 48 | plt.figure(figsize=(12, 8)) 49 | ax = sns.barplot(x=top_makes.values, y=top_makes.index, palette=custom_palette) 50 | plt.title("Top 10 EV Manufacturers", fontsize=18, pad=20) 51 | plt.xlabel("Number of Vehicles", fontsize=14) 52 | plt.ylabel("Make", fontsize=14) 53 | for i, v in enumerate(top_makes.values): 54 | ax.text(v + 0.1, i, str(v), color='black', fontweight='bold') 55 | plt.tight_layout() 56 | plt.show() 57 | 58 | # 6. Top 10 EV Models 59 | top_models = df['Model'].value_counts().head(10) 60 | plt.figure(figsize=(12, 8)) 61 | ax = sns.barplot(x=top_models.values, y=top_models.index, palette=custom_palette) 62 | plt.title("Top 10 EV Models", fontsize=18, pad=20) 63 | plt.xlabel("Number of Vehicles", fontsize=14) 64 | plt.ylabel("Model", fontsize=14) 65 | for i, v in enumerate(top_models.values): 66 | ax.text(v + 0.1, i, str(v), color='black', fontweight='bold') 67 | plt.tight_layout() 68 | plt.show() 69 | 70 | # 7. Distribution of EV Types 71 | type_counts = df['Electric Vehicle Type'].value_counts() 72 | plt.figure(figsize=(10, 8)) 73 | colors = sns.color_palette("Set2", len(type_counts)) 74 | labels = [f"{label}\n({count:,} - {count/sum(type_counts)*100:.1f}%)" for label, count in type_counts.items()] 75 | plt.pie(type_counts, labels=labels, startangle=140, colors=colors, 76 | wedgeprops={'edgecolor': 'white', 'linewidth': 2}, 77 | textprops={'fontsize': 12}) 78 | plt.title("Distribution of Electric Vehicle Types", fontsize=18, pad=20) 79 | plt.axis('equal') 80 | plt.tight_layout() 81 | plt.show() 82 | 83 | # 8. Top Cities by EV Count 84 | top_cities = df['City'].value_counts().head(10) 85 | plt.figure(figsize=(12, 8)) 86 | ax = sns.barplot(x=top_cities.values, y=top_cities.index, palette=custom_palette) 87 | plt.title("Top 10 Cities by EV Count", fontsize=18, pad=20) 88 | plt.xlabel("Number of EVs", fontsize=14) 89 | plt.ylabel("City", fontsize=14) 90 | for i, v in enumerate(top_cities.values): 91 | ax.text(v + 0.1, i, str(v), color='black', fontweight='bold') 92 | plt.tight_layout() 93 | plt.show() 94 | 95 | # 9. Year-over-Year Growth Rate 96 | ev_growth["Yearly Growth Rate (%)"] = ev_growth["Number of EVs"].pct_change() * 100 97 | plt.figure(figsize=(12, 8)) 98 | ax = sns.barplot(data=ev_growth[1:], x="Model Year", y="Yearly Growth Rate (%)", 99 | palette=custom_palette) 100 | plt.title("Year-over-Year EV Growth Rate", fontsize=18, pad=20) 101 | plt.xlabel("Model Year", fontsize=14) 102 | plt.ylabel("Growth Rate (%)", fontsize=14) 103 | plt.xticks(rotation=45) 104 | for i, v in enumerate(ev_growth[1:]["Yearly Growth Rate (%)"]): 105 | ax.text(i, v + 0.1, f"{v:.1f}%", ha='center', color='black', fontweight='bold') 106 | plt.tight_layout() 107 | plt.show() 108 | 109 | # 10. Top EV Models by Type 110 | top_models_by_type = df.groupby(['Electric Vehicle Type', 'Model']).size().reset_index(name='Count') 111 | top_models_by_type = top_models_by_type.sort_values('Count', ascending=False).groupby('Electric Vehicle Type').head(5) 112 | 113 | plt.figure(figsize=(14, 8)) 114 | sns.barplot(data=top_models_by_type, y='Model', x='Count', 115 | hue='Electric Vehicle Type', palette=custom_palette) 116 | plt.title("Top 5 EV Models by Type (BEV vs PHEV)", fontsize=18, pad=20) 117 | plt.xlabel("Number of EVs", fontsize=14) 118 | plt.ylabel("Model", fontsize=14) 119 | plt.legend(title='Vehicle Type', title_fontsize=12, fontsize=12) 120 | plt.tight_layout() 121 | plt.show() 122 | 123 | # 11. Correlation Heatmap 124 | numerical_cols = ['Model Year', 'Electric Range', 'Base MSRP'] 125 | plt.figure(figsize=(10, 8)) 126 | sns.heatmap(df[numerical_cols].corr(), annot=True, cmap='coolwarm', 127 | fmt=".2f", linewidths=0.5, square=True) 128 | plt.title("Correlation Heatmap", fontsize=18, pad=20) 129 | plt.tight_layout() 130 | plt.show() 131 | 132 | # 12. Average Electric Range Over Time 133 | avg_range_by_year = df.groupby("Model Year")["Electric Range"].mean().reset_index() 134 | 135 | plt.figure(figsize=(12, 8)) 136 | sns.lineplot(data=avg_range_by_year, x="Model Year", y="Electric Range", 137 | marker="o", linewidth=2.5, color=custom_palette[2]) 138 | plt.title("Average Electric Range Over Time", fontsize=18, pad=20) 139 | plt.xlabel("Model Year", fontsize=14) 140 | plt.ylabel("Average Electric Range (miles)", fontsize=14) 141 | plt.xticks(rotation=45) 142 | plt.grid(True, alpha=0.3) 143 | plt.tight_layout() 144 | plt.show() 145 | 146 | # 13. Average EVs per City Over Time 147 | avg_city_count = df.groupby(['Model Year', 'City']).size().groupby('Model Year').mean().reset_index(name='Average EVs per City') 148 | 149 | plt.figure(figsize=(12, 8)) 150 | sns.lineplot(data=avg_city_count, x="Model Year", y="Average EVs per City", 151 | marker="o", color=custom_palette[3], linewidth=2.5) 152 | plt.title("Average EVs per City Over Time", fontsize=18, pad=20) 153 | plt.xlabel("Model Year", fontsize=14) 154 | plt.ylabel("Average Count", fontsize=14) 155 | plt.xticks(rotation=45) 156 | plt.grid(True, alpha=0.3) 157 | plt.tight_layout() 158 | plt.show() 159 | 160 | # 14. Average MSRP Over Time 161 | avg_msrp_by_year = df.groupby("Model Year")["Base MSRP"].mean().reset_index() 162 | 163 | plt.figure(figsize=(12, 8)) 164 | sns.lineplot(data=avg_msrp_by_year, x="Model Year", y="Base MSRP", 165 | marker="o", color=custom_palette[4], linewidth=2.5) 166 | plt.title("Average MSRP Over Time", fontsize=18, pad=20) 167 | plt.xlabel("Model Year", fontsize=14) 168 | plt.ylabel("Average MSRP (USD)", fontsize=14) 169 | plt.xticks(rotation=45) 170 | plt.grid(True, alpha=0.3) 171 | plt.tight_layout() 172 | plt.show() 173 | 174 | # 15. MSRP Distribution by Electric Vehicle Type 175 | msrp_trend = df.groupby("Model Year")["Base MSRP"].mean().reset_index() 176 | plt.figure(figsize=(12, 8)) 177 | sns.lineplot(data=msrp_trend, x="Model Year", y="Base MSRP", 178 | marker="o", color=custom_palette[5], linewidth=2.5) 179 | plt.title("Average MSRP of EVs Over Time", fontsize=18, pad=20) 180 | plt.xlabel("Model Year", fontsize=14) 181 | plt.ylabel("Base MSRP (USD)", fontsize=14) 182 | plt.xticks(rotation=45) 183 | plt.grid(True, alpha=0.3) 184 | plt.tight_layout() 185 | plt.show() 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /ums python.txt: -------------------------------------------------------------------------------- 1 | # 1. Importing Required Libraries 2 | import numpy as np 3 | import pandas as pd 4 | import matplotlib.pyplot as plt 5 | import seaborn as sns 6 | 7 | # Display settings 8 | plt.style.use('seaborn-v0_8') # Using the correct style name 9 | sns.set_style("whitegrid") 10 | plt.rcParams['figure.figsize'] = [12, 8] 11 | plt.rcParams['font.size'] = 12 12 | plt.rcParams['axes.labelsize'] = 14 13 | plt.rcParams['axes.titlesize'] = 16 14 | plt.rcParams['xtick.labelsize'] = 12 15 | plt.rcParams['ytick.labelsize'] = 12 16 | plt.rcParams['axes.grid'] = True 17 | plt.rcParams['grid.alpha'] = 0.3 18 | plt.rcParams['figure.dpi'] = 100 19 | 20 | # Custom color palette 21 | custom_palette = sns.color_palette("husl", 8) 22 | 23 | # 2. Loading the Dataset 24 | df = pd.read_csv("project.csv") 25 | 26 | # 3. Data Cleaning 27 | df.dropna(inplace=True) 28 | df.drop(columns=["State"], inplace=True) 29 | df.drop_duplicates(inplace=True) 30 | 31 | # 4. EV Growth Over Time 32 | ev_growth = df.groupby("Model Year").size().reset_index(name="Number of EVs") 33 | plt.figure(figsize=(14, 7)) 34 | sns.lineplot(data=ev_growth, x="Model Year", y="Number of EVs", 35 | marker="o", linewidth=2.5, color=custom_palette[0]) 36 | plt.title("Growth of Electric Vehicles Over Time", fontsize=18, pad=20) 37 | plt.xlabel("Model Year", fontsize=14) 38 | plt.ylabel("Number of EVs Registered", fontsize=14) 39 | plt.xticks(rotation=45) 40 | plt.grid(True, alpha=0.3) 41 | plt.tight_layout() 42 | plt.show() 43 | 44 | # 5. Top 10 EV Manufacturers 45 | top_makes = df['Make'].value_counts().head(10) 46 | plt.figure(figsize=(12, 8)) 47 | ax = sns.barplot(x=top_makes.values, y=top_makes.index, palette=custom_palette) 48 | plt.title("Top 10 EV Manufacturers", fontsize=18, pad=20) 49 | plt.xlabel("Number of Vehicles", fontsize=14) 50 | plt.ylabel("Make", fontsize=14) 51 | for i, v in enumerate(top_makes.values): 52 | ax.text(v + 0.1, i, str(v), color='black', fontweight='bold') 53 | plt.tight_layout() 54 | plt.show() 55 | 56 | # 6. Top 10 EV Models 57 | top_models = df['Model'].value_counts().head(10) 58 | plt.figure(figsize=(12, 8)) 59 | ax = sns.barplot(x=top_models.values, y=top_models.index, palette=custom_palette) 60 | plt.title("Top 10 EV Models", fontsize=18, pad=20) 61 | plt.xlabel("Number of Vehicles", fontsize=14) 62 | plt.ylabel("Model", fontsize=14) 63 | for i, v in enumerate(top_models.values): 64 | ax.text(v + 0.1, i, str(v), color='black', fontweight='bold') 65 | plt.tight_layout() 66 | plt.show() 67 | 68 | # 7. Distribution of EV Types 69 | type_counts = df['Electric Vehicle Type'].value_counts() 70 | plt.figure(figsize=(10, 8)) 71 | colors = sns.color_palette("Set2", len(type_counts)) 72 | labels = [f"{label}\n({count:,} - {count/sum(type_counts)*100:.1f}%)" for label, count in type_counts.items()] 73 | plt.pie(type_counts, labels=labels, startangle=140, colors=colors, 74 | wedgeprops={'edgecolor': 'white', 'linewidth': 2}, 75 | textprops={'fontsize': 12}) 76 | plt.title("Distribution of Electric Vehicle Types", fontsize=18, pad=20) 77 | plt.axis('equal') 78 | plt.tight_layout() 79 | plt.show() 80 | 81 | # 8. Top Cities by EV Count 82 | top_cities = df['City'].value_counts().head(10) 83 | plt.figure(figsize=(12, 8)) 84 | ax = sns.barplot(x=top_cities.values, y=top_cities.index, palette=custom_palette) 85 | plt.title("Top 10 Cities by EV Count", fontsize=18, pad=20) 86 | plt.xlabel("Number of EVs", fontsize=14) 87 | plt.ylabel("City", fontsize=14) 88 | for i, v in enumerate(top_cities.values): 89 | ax.text(v + 0.1, i, str(v), color='black', fontweight='bold') 90 | plt.tight_layout() 91 | plt.show() 92 | 93 | # 9. Year-over-Year Growth Rate 94 | ev_growth["Yearly Growth Rate (%)"] = ev_growth["Number of EVs"].pct_change() * 100 95 | plt.figure(figsize=(12, 8)) 96 | ax = sns.barplot(data=ev_growth[1:], x="Model Year", y="Yearly Growth Rate (%)", 97 | palette=custom_palette) 98 | plt.title("Year-over-Year EV Growth Rate", fontsize=18, pad=20) 99 | plt.xlabel("Model Year", fontsize=14) 100 | plt.ylabel("Growth Rate (%)", fontsize=14) 101 | plt.xticks(rotation=45) 102 | for i, v in enumerate(ev_growth[1:]["Yearly Growth Rate (%)"]): 103 | ax.text(i, v + 0.1, f"{v:.1f}%", ha='center', color='black', fontweight='bold') 104 | plt.tight_layout() 105 | plt.show() 106 | 107 | # 10. Top EV Models by Type 108 | top_models_by_type = df.groupby(['Electric Vehicle Type', 'Model']).size().reset_index(name='Count') 109 | top_models_by_type = top_models_by_type.sort_values('Count', ascending=False).groupby('Electric Vehicle Type').head(5) 110 | 111 | plt.figure(figsize=(14, 8)) 112 | sns.barplot(data=top_models_by_type, y='Model', x='Count', 113 | hue='Electric Vehicle Type', palette=custom_palette) 114 | plt.title("Top 5 EV Models by Type (BEV vs PHEV)", fontsize=18, pad=20) 115 | plt.xlabel("Number of EVs", fontsize=14) 116 | plt.ylabel("Model", fontsize=14) 117 | plt.legend(title='Vehicle Type', title_fontsize=12, fontsize=12) 118 | plt.tight_layout() 119 | plt.show() 120 | 121 | # 11. Correlation Heatmap 122 | numerical_cols = ['Model Year', 'Electric Range', 'Base MSRP'] 123 | plt.figure(figsize=(10, 8)) 124 | sns.heatmap(df[numerical_cols].corr(), annot=True, cmap='coolwarm', 125 | fmt=".2f", linewidths=0.5, square=True) 126 | plt.title("Correlation Heatmap", fontsize=18, pad=20) 127 | plt.tight_layout() 128 | plt.show() 129 | 130 | # 12. Average Electric Range Over Time 131 | avg_range_by_year = df.groupby("Model Year")["Electric Range"].mean().reset_index() 132 | 133 | plt.figure(figsize=(12, 8)) 134 | sns.lineplot(data=avg_range_by_year, x="Model Year", y="Electric Range", 135 | marker="o", linewidth=2.5, color=custom_palette[2]) 136 | plt.title("Average Electric Range Over Time", fontsize=18, pad=20) 137 | plt.xlabel("Model Year", fontsize=14) 138 | plt.ylabel("Average Electric Range (miles)", fontsize=14) 139 | plt.xticks(rotation=45) 140 | plt.grid(True, alpha=0.3) 141 | plt.tight_layout() 142 | plt.show() 143 | 144 | # 13. Average EVs per City Over Time 145 | avg_city_count = df.groupby(['Model Year', 'City']).size().groupby('Model Year').mean().reset_index(name='Average EVs per City') 146 | 147 | plt.figure(figsize=(12, 8)) 148 | sns.lineplot(data=avg_city_count, x="Model Year", y="Average EVs per City", 149 | marker="o", color=custom_palette[3], linewidth=2.5) 150 | plt.title("Average EVs per City Over Time", fontsize=18, pad=20) 151 | plt.xlabel("Model Year", fontsize=14) 152 | plt.ylabel("Average Count", fontsize=14) 153 | plt.xticks(rotation=45) 154 | plt.grid(True, alpha=0.3) 155 | plt.tight_layout() 156 | plt.show() 157 | 158 | # 14. Average MSRP Over Time 159 | avg_msrp_by_year = df.groupby("Model Year")["Base MSRP"].mean().reset_index() 160 | 161 | plt.figure(figsize=(12, 8)) 162 | sns.lineplot(data=avg_msrp_by_year, x="Model Year", y="Base MSRP", 163 | marker="o", color=custom_palette[4], linewidth=2.5) 164 | plt.title("Average MSRP Over Time", fontsize=18, pad=20) 165 | plt.xlabel("Model Year", fontsize=14) 166 | plt.ylabel("Average MSRP (USD)", fontsize=14) 167 | plt.xticks(rotation=45) 168 | plt.grid(True, alpha=0.3) 169 | plt.tight_layout() 170 | plt.show() 171 | 172 | # 15. MSRP Distribution by Electric Vehicle Type 173 | msrp_trend = df.groupby("Model Year")["Base MSRP"].mean().reset_index() 174 | plt.figure(figsize=(12, 8)) 175 | sns.lineplot(data=msrp_trend, x="Model Year", y="Base MSRP", 176 | marker="o", color=custom_palette[5], linewidth=2.5) 177 | plt.title("Average MSRP of EVs Over Time", fontsize=18, pad=20) 178 | plt.xlabel("Model Year", fontsize=14) 179 | plt.ylabel("Base MSRP (USD)", fontsize=14) 180 | plt.xticks(rotation=45) 181 | plt.grid(True, alpha=0.3) 182 | plt.tight_layout() 183 | plt.show() 184 | 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /ums python2.txt: -------------------------------------------------------------------------------- 1 | 2 | import streamlit as st 3 | import pandas as pd 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import seaborn as sns 7 | from datetime import datetime 8 | 9 | # Set style and color palette 10 | plt.style.use('seaborn-v0_8') 11 | sns.set_style("whitegrid") 12 | plt.rcParams['figure.figsize'] = [12, 8] 13 | plt.rcParams['font.size'] = 12 14 | plt.rcParams['axes.labelsize'] = 14 15 | plt.rcParams['axes.titlesize'] = 16 16 | plt.rcParams['xtick.labelsize'] = 12 17 | plt.rcParams['ytick.labelsize'] = 12 18 | plt.rcParams['axes.grid'] = True 19 | plt.rcParams['grid.alpha'] = 0.3 20 | plt.rcParams['figure.dpi'] = 100 21 | 22 | # Custom color palette 23 | custom_palette = sns.color_palette("husl", 8) 24 | 25 | # Set page configuration 26 | st.set_page_config( 27 | page_title="Electric Vehicle Analytics Dashboard", 28 | page_icon="🚗", 29 | layout="wide", 30 | initial_sidebar_state="expanded" 31 | ) 32 | 33 | # Custom styling 34 | st.markdown(""" 35 | 152 | """, unsafe_allow_html=True) 153 | 154 | # Define helper functions 155 | def filter_summary(years, types, price_range, range_values): 156 | st.markdown(f""" 157 |
158 |

Active Filters

159 | 165 |
166 | """, unsafe_allow_html=True) 167 | 168 | def section_header(title, description): 169 | st.markdown(f""" 170 |
171 |

{title}

172 |

{description}

173 |
174 | """, unsafe_allow_html=True) 175 | 176 | def footer(): 177 | st.markdown(f""" 178 |
179 |

Electric Vehicle Analytics Dashboard

180 |

Last Updated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}

181 |

Data refreshed automatically on load

182 |
183 | """, unsafe_allow_html=True) 184 | 185 | # Load data 186 | @st.cache_data 187 | def load_data(): 188 | df = pd.read_csv("project.csv") 189 | df.dropna(inplace=True) 190 | df.drop(columns=["State"], inplace=True) 191 | df.drop_duplicates(inplace=True) 192 | return df 193 | 194 | # Load the data 195 | df = load_data() 196 | 197 | # Sidebar with enhanced styling 198 | with st.sidebar: 199 | st.title("📊 Dashboard Controls") 200 | st.markdown("---") 201 | 202 | # Update the dashboard description box styling 203 | st.markdown(""" 204 |
205 |

About this Dashboard

206 |

207 | Explore electric vehicle trends, distributions, and patterns using interactive filters below. 208 |

209 |
210 | """, unsafe_allow_html=True) 211 | 212 | # Filters in expandable sections 213 | with st.expander("🔍 Time Period Filter", expanded=True): 214 | # Year range selector with min/max display 215 | min_year = int(df['Model Year'].min()) 216 | max_year = int(df['Model Year'].max()) 217 | selected_years = st.slider( 218 | "Select Year Range", 219 | min_value=min_year, 220 | max_value=max_year, 221 | value=(min_year, max_year) 222 | ) 223 | st.caption(f"Selected period: {selected_years[0]} - {selected_years[1]}") 224 | 225 | with st.expander("🚗 Vehicle Type Filter", expanded=True): 226 | # Vehicle type filter with select all/none options 227 | all_types = df['Electric Vehicle Type'].unique() 228 | select_all = st.checkbox("Select All Types", value=True) 229 | 230 | if select_all: 231 | vehicle_types = st.multiselect( 232 | "Choose Vehicle Types", 233 | options=all_types, 234 | default=all_types 235 | ) 236 | else: 237 | vehicle_types = st.multiselect( 238 | "Choose Vehicle Types", 239 | options=all_types 240 | ) 241 | 242 | with st.expander("📈 Additional Filters", expanded=False): 243 | # Price range filter 244 | price_range = st.slider( 245 | "Price Range (MSRP)", 246 | min_value=float(df['Base MSRP'].min()), 247 | max_value=float(df['Base MSRP'].max()), 248 | value=(float(df['Base MSRP'].min()), float(df['Base MSRP'].max())), 249 | format="$%f" 250 | ) 251 | 252 | # Range filter 253 | range_values = st.slider( 254 | "Electric Range (miles)", 255 | min_value=int(df['Electric Range'].min()), 256 | max_value=int(df['Electric Range'].max()), 257 | value=(int(df['Electric Range'].min()), int(df['Electric Range'].max())) 258 | ) 259 | 260 | # Update the filter summary call in the sidebar 261 | filter_summary(selected_years, vehicle_types, price_range, range_values) 262 | 263 | # Add separator 264 | st.markdown("---") 265 | 266 | # About Me Section 267 | st.markdown(""" 268 |
269 |

👨‍🎓 About Me

270 |
271 |

Name:AMAN KUMAR

272 |

Reg. Number:12318896

273 |

Section:K23GP

274 |

Course:BTECH-CSE

275 |
276 |

277 | Academic Project - Electric Vehicle Analytics Dashboard 278 |

279 |
280 |
281 |
282 | """, unsafe_allow_html=True) 283 | 284 | # Apply filters to the dataframe 285 | filtered_df = df[ 286 | (df['Model Year'] >= selected_years[0]) & 287 | (df['Model Year'] <= selected_years[1]) & 288 | (df['Electric Vehicle Type'].isin(vehicle_types)) & 289 | (df['Base MSRP'] >= price_range[0]) & 290 | (df['Base MSRP'] <= price_range[1]) & 291 | (df['Electric Range'] >= range_values[0]) & 292 | (df['Electric Range'] <= range_values[1]) 293 | ] 294 | 295 | # Main content 296 | st.title("🚗 Electric Vehicle Analytics Dashboard") 297 | st.markdown(""" 298 |
299 |

300 | Comprehensive analysis of electric vehicle trends and patterns across different dimensions. 301 |

302 |
303 | """, unsafe_allow_html=True) 304 | 305 | # Key Metrics with enhanced styling 306 | st.markdown(""" 307 |
308 |

Key Metrics Overview

309 |
310 | """, unsafe_allow_html=True) 311 | 312 | col1, col2, col3, col4 = st.columns(4) 313 | with col1: 314 | st.metric( 315 | "Total Vehicles", 316 | f"{len(filtered_df):,}" 317 | ) 318 | with col2: 319 | st.metric( 320 | "Average Range", 321 | f"{filtered_df['Electric Range'].mean():.0f} miles" 322 | ) 323 | with col3: 324 | st.metric( 325 | "Average MSRP", 326 | f"${filtered_df['Base MSRP'].mean():,.0f}" 327 | ) 328 | with col4: 329 | st.metric( 330 | "Unique Models", 331 | f"{filtered_df['Model'].nunique():,}" 332 | ) 333 | 334 | # Continue with the existing visualization code, but add section headers with enhanced styling 335 | st.markdown("---") 336 | 337 | # Add section headers with enhanced styling before each row 338 | def section_header(title, description): 339 | st.markdown(f""" 340 |
341 |

{title}

342 |

{description}

343 |
344 | """, unsafe_allow_html=True) 345 | 346 | # First Row 347 | section_header( 348 | "Growth Trends & Distribution", 349 | "Analysis of EV adoption over time and distribution of vehicle types" 350 | ) 351 | row1_col1, row1_col2 = st.columns(2) 352 | 353 | # Left Column - Growth and Trends 354 | with row1_col1: 355 | st.subheader("Growth and Trends") 356 | 357 | # EV Growth Over Time 358 | ev_growth = filtered_df.groupby("Model Year").size().reset_index(name="Number of EVs") 359 | fig, ax = plt.subplots(figsize=(10, 6)) 360 | sns.lineplot(data=ev_growth, x="Model Year", y="Number of EVs", 361 | marker="o", linewidth=2.5, color='#1f77b4') 362 | plt.title("Growth of Electric Vehicles Over Time") 363 | plt.grid(True, alpha=0.3) 364 | plt.xticks(rotation=45) 365 | plt.tight_layout() 366 | st.pyplot(fig) 367 | 368 | # Right Column - Distribution 369 | with row1_col2: 370 | st.subheader("Distribution and Composition") 371 | 372 | # Vehicle Type Distribution 373 | type_counts = filtered_df['Electric Vehicle Type'].value_counts() 374 | fig, ax = plt.subplots(figsize=(10, 6)) 375 | colors = sns.color_palette("Set2", len(type_counts)) 376 | plt.pie(type_counts, labels=type_counts.index, autopct='%1.1f%%', 377 | colors=colors, wedgeprops={'edgecolor': 'white', 'linewidth': 2}) 378 | plt.title("Distribution of Electric Vehicle Types") 379 | plt.axis('equal') 380 | plt.tight_layout() 381 | st.pyplot(fig) 382 | 383 | st.markdown("---") 384 | 385 | # Second Row - Models and Range 386 | row2_col1, row2_col2 = st.columns(2) 387 | 388 | with row2_col1: 389 | st.subheader("Top EV Models") 390 | # Top Models 391 | top_models = filtered_df['Model'].value_counts().head(10) 392 | fig, ax = plt.subplots(figsize=(10, 6)) 393 | sns.barplot(x=top_models.values, y=top_models.index, palette="magma") 394 | plt.title("Top 10 EV Models") 395 | for i, v in enumerate(top_models.values): 396 | ax.text(v + 0.1, i, str(v), color='black', fontweight='bold') 397 | plt.tight_layout() 398 | st.pyplot(fig) 399 | 400 | with row2_col2: 401 | st.subheader("Range Analysis") 402 | # Average Range Over Time 403 | avg_range = filtered_df.groupby("Model Year")["Electric Range"].mean().reset_index() 404 | fig, ax = plt.subplots(figsize=(10, 6)) 405 | sns.lineplot(data=avg_range, x="Model Year", y="Electric Range", 406 | marker="o", linewidth=2.5, color='#2ca02c') 407 | plt.title("Average Electric Range Over Time") 408 | plt.grid(True, alpha=0.3) 409 | plt.xticks(rotation=45) 410 | plt.tight_layout() 411 | st.pyplot(fig) 412 | 413 | st.markdown("---") 414 | 415 | # Third Row - Price Analysis and Cities 416 | row3_col1, row3_col2 = st.columns(2) 417 | 418 | with row3_col1: 419 | st.subheader("Price Analysis") 420 | # Average MSRP Over Time 421 | avg_msrp = filtered_df.groupby("Model Year")["Base MSRP"].mean().reset_index() 422 | fig, ax = plt.subplots(figsize=(10, 6)) 423 | sns.lineplot(data=avg_msrp, x="Model Year", y="Base MSRP", 424 | marker="o", linewidth=2.5, color='#ff7f0e') 425 | plt.title("Average MSRP Over Time") 426 | plt.grid(True, alpha=0.3) 427 | plt.xticks(rotation=45) 428 | plt.tight_layout() 429 | st.pyplot(fig) 430 | 431 | with row3_col2: 432 | st.subheader("Geographic Distribution") 433 | # Top Cities 434 | top_cities = filtered_df['City'].value_counts().head(10) 435 | fig, ax = plt.subplots(figsize=(10, 6)) 436 | sns.barplot(x=top_cities.values, y=top_cities.index, palette="coolwarm") 437 | plt.title("Top 10 Cities by EV Count") 438 | for i, v in enumerate(top_cities.values): 439 | ax.text(v + 0.1, i, str(v), color='black', fontweight='bold') 440 | plt.tight_layout() 441 | st.pyplot(fig) 442 | 443 | # After the third row (Price Analysis and Cities), add new rows: 444 | 445 | st.markdown("---") 446 | 447 | # Fourth Row - Growth Rate and Manufacturers 448 | row4_col1, row4_col2 = st.columns(2) 449 | 450 | with row4_col1: 451 | st.subheader("Year-over-Year Growth Rate") 452 | # Growth Rate Analysis 453 | ev_growth["Yearly Growth Rate (%)"] = ev_growth["Number of EVs"].pct_change() * 100 454 | fig, ax = plt.subplots(figsize=(10, 6)) 455 | sns.barplot(data=ev_growth[1:], x="Model Year", y="Yearly Growth Rate (%)", 456 | palette=custom_palette) 457 | plt.title("Year-over-Year EV Growth Rate") 458 | plt.xticks(rotation=45) 459 | for i, v in enumerate(ev_growth[1:]["Yearly Growth Rate (%)"]): 460 | ax.text(i, v + 0.1, f"{v:.1f}%", ha='center', color='black', fontweight='bold') 461 | plt.tight_layout() 462 | st.pyplot(fig) 463 | 464 | with row4_col2: 465 | st.subheader("Top Manufacturers") 466 | # Top Manufacturers 467 | top_makes = filtered_df['Make'].value_counts().head(10) 468 | fig, ax = plt.subplots(figsize=(10, 6)) 469 | sns.barplot(x=top_makes.values, y=top_makes.index, palette=custom_palette) 470 | plt.title("Top 10 EV Manufacturers") 471 | for i, v in enumerate(top_makes.values): 472 | ax.text(v + 0.1, i, str(v), color='black', fontweight='bold') 473 | plt.tight_layout() 474 | st.pyplot(fig) 475 | 476 | st.markdown("---") 477 | 478 | # Fifth Row - Models by Type and Correlation 479 | row5_col1, row5_col2 = st.columns(2) 480 | 481 | with row5_col1: 482 | st.subheader("Top Models by Vehicle Type") 483 | # Models by Type 484 | top_models_by_type = filtered_df.groupby(['Electric Vehicle Type', 'Model']).size().reset_index(name='Count') 485 | top_models_by_type = top_models_by_type.sort_values('Count', ascending=False).groupby('Electric Vehicle Type').head(5) 486 | fig, ax = plt.subplots(figsize=(10, 6)) 487 | sns.barplot(data=top_models_by_type, y='Model', x='Count', 488 | hue='Electric Vehicle Type', palette=custom_palette) 489 | plt.title("Top 5 EV Models by Type") 490 | plt.legend(title='Vehicle Type', title_fontsize=12, fontsize=10) 491 | plt.tight_layout() 492 | st.pyplot(fig) 493 | 494 | with row5_col2: 495 | st.subheader("Correlation Analysis") 496 | # Correlation Heatmap 497 | numerical_cols = ['Model Year', 'Electric Range', 'Base MSRP'] 498 | fig, ax = plt.subplots(figsize=(10, 6)) 499 | sns.heatmap(filtered_df[numerical_cols].corr(), annot=True, 500 | cmap='coolwarm', fmt=".2f", linewidths=0.5, square=True) 501 | plt.title("Correlation Heatmap") 502 | plt.tight_layout() 503 | st.pyplot(fig) 504 | 505 | st.markdown("---") 506 | 507 | # Sixth Row - Average EVs per City and MSRP Distribution 508 | row6_col1, row6_col2 = st.columns(2) 509 | 510 | with row6_col1: 511 | st.subheader("City-wise EV Distribution") 512 | # Average EVs per City Over Time 513 | avg_city_count = filtered_df.groupby(['Model Year', 'City']).size().groupby('Model Year').mean().reset_index(name='Average EVs per City') 514 | fig, ax = plt.subplots(figsize=(10, 6)) 515 | sns.lineplot(data=avg_city_count, x="Model Year", y="Average EVs per City", 516 | marker="o", color=custom_palette[3], linewidth=2.5) 517 | plt.title("Average EVs per City Over Time") 518 | plt.grid(True, alpha=0.3) 519 | plt.xticks(rotation=45) 520 | plt.tight_layout() 521 | st.pyplot(fig) 522 | 523 | with row6_col2: 524 | st.subheader("MSRP Distribution") 525 | # MSRP Distribution by Vehicle Type 526 | fig, ax = plt.subplots(figsize=(10, 6)) 527 | sns.boxplot(data=filtered_df, x='Electric Vehicle Type', y='Base MSRP', 528 | palette=custom_palette) 529 | plt.title("MSRP Distribution by Vehicle Type") 530 | plt.xticks(rotation=45) 531 | plt.tight_layout() 532 | st.pyplot(fig) 533 | --------------------------------------------------------------------------------