├── README.md └── python code1.py /README.md: -------------------------------------------------------------------------------- 1 | #PYTHON PROJECT 2 | 3 | -------------------------------------------------------------------------------- /python code1.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import matplotlib.pyplot as plt 3 | import seaborn as sns 4 | 5 | # Load CSV 6 | file_path = r"C:\Users\asus\OneDrive\Attachments\python project\Electric_Vehicle_Population_Data.csv" 7 | df = pd.read_csv(file_path) 8 | #gggggggghukgukg 9 | #ukglhlihl 10 | # Auto-detect columns 11 | numerical_cols = df.select_dtypes(include=['int64', 'float64']).columns 12 | categorical_cols = df.select_dtypes(include=['object', 'category']).columns 13 | 14 | sns.set(style="whitegrid") 15 | 16 | # 1️⃣ Scatter Plot 17 | if len(numerical_cols) >= 2: 18 | plt.figure(figsize=(8, 5)) 19 | sns.scatterplot(data=df, x=numerical_cols[0], y=numerical_cols[1]) 20 | plt.title(f"Scatter Plot: {numerical_cols[0]} vs {numerical_cols[1]}") 21 | plt.tight_layout() 22 | plt.show() 23 | 24 | # 2️⃣ Area Plot 25 | if 'Model Year' in df.columns: 26 | year_data = df['Model Year'].value_counts().sort_index() 27 | plt.figure(figsize=(8, 5)) 28 | plt.fill_between(year_data.index, year_data.values, color="skyblue", alpha=0.4) 29 | plt.plot(year_data.index, year_data.values, color="Slateblue", alpha=0.6) 30 | plt.title("EV Registration Over Years") 31 | plt.xlabel("Year") 32 | plt.ylabel("Number of EVs") 33 | plt.tight_layout() 34 | plt.show() 35 | 36 | # 3️⃣ Heatmap 37 | if len(numerical_cols) >= 2: 38 | plt.figure(figsize=(10, 6)) 39 | corr = df[numerical_cols].corr() 40 | sns.heatmap(corr, annot=True, cmap='coolwarm', linewidths=0.5) 41 | plt.title("Correlation Heatmap") 42 | plt.tight_layout() 43 | plt.show() 44 | 45 | # 4️⃣ Donut Chart 46 | if 'Make' in df.columns: 47 | top_makes = df['Make'].value_counts().nlargest(5) 48 | plt.figure(figsize=(6, 6)) 49 | wedges, texts, autotexts = plt.pie(top_makes, autopct='%1.1f%%', startangle=90, wedgeprops=dict(width=0.4)) 50 | plt.title("Top 5 Vehicle Makes - Donut Chart") 51 | plt.legend(top_makes.index, title="Make", loc="center left", bbox_to_anchor=(1, 0, 0.5, 1)) 52 | plt.tight_layout() 53 | plt.show() 54 | 55 | # 5️⃣ Violin Plot 56 | if len(numerical_cols) >= 1 and 'Electric Vehicle Type' in df.columns: 57 | plt.figure(figsize=(8, 5)) 58 | sns.violinplot(data=df, x='Electric Vehicle Type', y=numerical_cols[0]) 59 | plt.title(f"Violin Plot of {numerical_cols[0]} by Electric Vehicle Type") 60 | plt.xticks(rotation=45) 61 | plt.tight_layout() 62 | plt.show() 63 | 64 | # 6️⃣ Countplot with hue 65 | if 'Electric Vehicle Type' in df.columns and 'Make' in df.columns: 66 | top_5_makes = df['Make'].value_counts().nlargest(5).index 67 | filtered_df = df[df['Make'].isin(top_5_makes)] 68 | plt.figure(figsize=(10, 5)) 69 | sns.countplot(data=filtered_df, x='Make', hue='Electric Vehicle Type') 70 | plt.title("Countplot with Hue (Make vs EV Type)") 71 | plt.tight_layout() 72 | plt.show() 73 | 74 | # 7️⃣ Pairplot 75 | if len(numerical_cols) >= 2: 76 | sns.pairplot(df[numerical_cols].dropna().sample(n=min(100, len(df))), diag_kind='kde') 77 | plt.suptitle("Pairplot of Numerical Features", y=1.02) 78 | plt.show() 79 | 80 | # 8️⃣ Swarmplot 81 | if len(numerical_cols) >= 1 and 'Electric Vehicle Type' in df.columns: 82 | plt.figure(figsize=(8, 5)) 83 | sns.swarmplot(data=df, x='Electric Vehicle Type', y=numerical_cols[0]) 84 | plt.title(f"Swarmplot of {numerical_cols[0]}") 85 | plt.xticks(rotation=45) 86 | plt.tight_layout() 87 | plt.show() 88 | 89 | # 9️⃣ Stripplot 90 | if len(numerical_cols) >= 1 and 'Electric Vehicle Type' in df.columns: 91 | plt.figure(figsize=(8, 5)) 92 | sns.stripplot(data=df, x='Electric Vehicle Type', y=numerical_cols[0], jitter=True) 93 | plt.title(f"Stripplot of {numerical_cols[0]}") 94 | plt.xticks(rotation=45) 95 | plt.tight_layout() 96 | plt.show() 97 | 98 | # 🔟 FINAL DASHBOARD (2x2 grid) 99 | fig, axes = plt.subplots(2, 2, figsize=(14, 10)) 100 | 101 | # Histogram 102 | sns.histplot(df[numerical_cols[0]], kde=True, bins=30, ax=axes[0, 0]) 103 | axes[0, 0].set_title(f"Histogram of {numerical_cols[0]}") 104 | 105 | # Pie Chart 106 | if 'Make' in df.columns: 107 | top_makes = df['Make'].value_counts().nlargest(5) 108 | top_makes.plot.pie(autopct='%1.1f%%', ax=axes[0, 1], startangle=90) 109 | axes[0, 1].set_title("Top 5 Vehicle Makes - Pie Chart") 110 | axes[0, 1].set_ylabel("") 111 | 112 | # Bar Chart 113 | if 'Electric Vehicle Type' in df.columns: 114 | sns.countplot(data=df, x='Electric Vehicle Type', ax=axes[1, 0], order=df['Electric Vehicle Type'].value_counts().index) 115 | axes[1, 0].set_title("Bar Chart of Electric Vehicle Types") 116 | axes[1, 0].tick_params(axis='x', rotation=45) 117 | 118 | # Boxplot 119 | sns.boxplot(y=df[numerical_cols[1]], ax=axes[1, 1]) 120 | axes[1, 1].set_title(f"Boxplot of {numerical_cols[1]}") 121 | 122 | plt.tight_layout() 123 | plt.show() 124 | --------------------------------------------------------------------------------