-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask_1.py
More file actions
43 lines (33 loc) · 1.37 KB
/
Task_1.py
File metadata and controls
43 lines (33 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pandas as pd
import matplotlib.pyplot as plt
# Create dataset
data = {
"Name": ["Utkarsh", "Riya", "Tushar", "Ananya", "Om", "Isha", "Sahil", "Neha", "Umesh", "Simran"],
"Age": [18, 23, 18, 24, 19, 21, 19, 23, 20, 22],
"Gender": ["Male", "Female", "Male", "Female", "Male", "Female", "Male", "Female", "Male", "Female"]
}
df = pd.DataFrame(data)
print("Dataset:\n", df)
# ---------- Gender Distribution ----------
plt.figure(figsize=(6, 5))
gender_counts = df["Gender"].value_counts()
plt.bar(gender_counts.index, gender_counts.values, color=['skyblue', 'lightcoral'], edgecolor="black")
# Add labels above bars
for i, v in enumerate(gender_counts.values):
plt.text(i, v + 0.05, str(v), ha='center', fontweight='bold')
plt.title("Gender Distribution - Created by Kunal", fontsize=14, fontweight='bold')
plt.xlabel("Gender")
plt.ylabel("Count")
plt.show()
# ---------- Age Distribution ----------
plt.figure(figsize=(7, 5))
plt.style.use('ggplot') # different style
plt.hist(df["Age"], bins=6, color="mediumseagreen", edgecolor="black")
# Add mean line
mean_age = df["Age"].mean()
plt.axvline(mean_age, color='red', linestyle='dashed', linewidth=2, label=f'Mean Age: {mean_age:.1f}')
plt.legend()
plt.title("Age Distribution - Created by Kunal", fontsize=14, fontweight='bold')
plt.xlabel("Age")
plt.ylabel("Frequency")
plt.show()