├── README.md └── ca2.py /README.md: -------------------------------------------------------------------------------- 1 | # Python-project -------------------------------------------------------------------------------- /ca2.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | import seaborn as sns 5 | df=pd.read_csv(r"C:\Users\91934\OneDrive\Desktop\Electric_Vehicle_Population_Data.csv") 6 | print(df.isnull().sum()) 7 | df["County"]=df["County"].fillna(df["County"].mode()[0]) 8 | df["City"]=df["City"].fillna(df["City"].mode()[0]) 9 | df["Postal Code"]=df["Postal Code"].fillna(df["Postal Code"].median()) 10 | df["Legislative District"]=df["Legislative District"].fillna(df["Legislative District"].median()) 11 | df["Vehicle Location"]=df["Vehicle Location"].fillna(df["Vehicle Location"].mode()[0]) 12 | df["Electric Utility"]=df["Electric Utility"].fillna(df["Electric Utility"].mode()[0]) 13 | df["2020 Census Tract"]=df["2020 Census Tract"].fillna(df["2020 Census Tract"].mode()[0]) 14 | print(df.isnull().sum()) 15 | #1)Find out which electric vehicle types are common in top cities 16 | 17 | # Count vehicle types per city 18 | top_cities = df['City'].value_counts().head(10).index 19 | filtered = df[df['City'].isin(top_cities)] 20 | 21 | # Group by city and vehicle type 22 | type_counts = filtered.groupby(['City', 'Electric Vehicle Type']).size().unstack() 23 | type_counts.plot(kind='bar', figsize=(12,6)) 24 | plt.title("Electric Vehicle Types in Top Cities") 25 | plt.xlabel("City") 26 | plt.ylabel("Count") 27 | plt.xticks(rotation=45) 28 | plt.legend(title="Vehicle Type") 29 | plt.tight_layout() 30 | plt.show() 31 | 32 | # 2. Check how electric range changes across different vehicle makes 33 | 34 | plt.figure(figsize=(12,6)) 35 | sns.scatterplot(x="Make", y="Electric Range",data=df) 36 | plt.title("Electric Range by Vehicle Make") 37 | plt.xticks(rotation=90) 38 | plt.tight_layout() 39 | plt.show() 40 | 41 | 42 | #3 Compare number of EVs by model year 43 | model_year_counts = df['Model Year'].value_counts().sort_index() 44 | 45 | plt.figure(figsize=(10,5)) 46 | plt.bar(model_year_counts.index.astype(str), model_year_counts.values, color='skyblue') 47 | plt.xlabel("Model Year") 48 | plt.ylabel("Number of EVs") 49 | plt.title("EV Adoption by Model Year") 50 | plt.xticks(rotation=45) 51 | plt.tight_layout() 52 | plt.show() 53 | 54 | 55 | #4.Find the most popular vehicle in "make" and "model" 56 | top_makes = df['Make'].value_counts().head(5) 57 | 58 | plt.figure(figsize=(8,5)) 59 | plt.pie(top_makes.values, labels=top_makes.index, autopct='%1.1f%%', startangle=140) 60 | plt.title("Top 5 EV Makes") 61 | plt.show() 62 | 63 | # Optional: Top models 64 | top_models = df['Model'].value_counts().head(5) 65 | plt.figure(figsize=(8,5)) 66 | plt.bar(top_models.index, top_models.values, color='green') 67 | plt.title("Top 5 EV Models") 68 | plt.xlabel("Model") 69 | plt.ylabel("Count") 70 | plt.xticks(rotation=30) 71 | plt.tight_layout() 72 | plt.show() 73 | 74 | 75 | #5. Explore EV popularity by ZIP Code or City 76 | 77 | 78 | zip_counts = df['Postal Code'].value_counts().head(10) 79 | 80 | plt.figure(figsize=(10,6)) 81 | plt.bar(zip_counts.index.astype(str), zip_counts.values, color='orange') 82 | plt.title("Top 10 ZIP Codes with Most EVs") 83 | plt.xlabel("ZIP Code") 84 | plt.ylabel("Number of EVs") 85 | plt.xticks(rotation=45) 86 | plt.tight_layout() 87 | plt.show() 88 | 89 | 90 | 91 | #6.Finding out which electric car make is used the most by using a bar graph 92 | 93 | # Count the number of cars for each make 94 | make_counts = df['Make'].value_counts().head(10) # Top 10 makes 95 | 96 | # Create bar graph 97 | plt.figure(figsize=(10,5)) 98 | plt.bar(make_counts.index, make_counts.values, color='skyblue') 99 | plt.title("Top 10 Most Used Electric Vehicle Makes") 100 | plt.xlabel("Make") 101 | plt.ylabel("Number of Vehicles") 102 | plt.xticks(rotation=45) 103 | plt.tight_layout() 104 | plt.show() 105 | 106 | #7. This will show how many vehicles fall into different electric range values. 107 | 108 | # Histogram of Electric Range 109 | plt.figure(figsize=(10,5)) 110 | plt.hist(df['Electric Range'], bins=20, color='purple', edgecolor='black') 111 | plt.title("Distribution of Electric Range") 112 | plt.xlabel("Electric Range (miles)") 113 | plt.ylabel("Number of Vehicles") 114 | plt.grid() 115 | plt.tight_layout() 116 | plt.show() 117 | 118 | 119 | 120 | 121 | 122 | #8.Heatmap: Correlation Between Numeric Columns 123 | #This will show relationships between numeric features like Electric Range, Model Year 124 | 125 | 126 | # Selecting numeric columns for correlation 127 | numeric_data = df[['Model Year', 'Electric Range']] 128 | 129 | # Create the correlation matrix 130 | corr_matrix = numeric_data.corr() 131 | 132 | # Plot heatmap 133 | plt.figure(figsize=(6,4)) 134 | sns.heatmap(corr_matrix, annot=True, cmap="YlGnBu", linewidths=0.5) 135 | plt.title("Correlation Heatmap") 136 | plt.tight_layout() 137 | plt.show() 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | --------------------------------------------------------------------------------