├── 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 |
{description}
173 |Last Updated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
181 |Data refreshed automatically on load
182 |207 | Explore electric vehicle trends, distributions, and patterns using interactive filters below. 208 |
209 |Name:AMAN KUMAR
272 |Reg. Number:12318896
273 |Section:K23GP
274 |Course:BTECH-CSE
275 |277 | Academic Project - Electric Vehicle Analytics Dashboard 278 |
279 |300 | Comprehensive analysis of electric vehicle trends and patterns across different dimensions. 301 |
302 |{description}
343 |