-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
91 lines (77 loc) · 2.98 KB
/
analysis.py
File metadata and controls
91 lines (77 loc) · 2.98 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pandas as pd
import matplotlib.pyplot as plt
import os
file = "employees.csv"
if not os.path.exists(file):
df = pd.DataFrame(columns=[
"EmpID", "Name", "Department", "Designation",
"Salary", "Age", "Experience"
])
df.to_csv(file, index=False)
df = pd.read_csv(file)
while True:
print("\n========== GRAPHICAL EMPLOYEE ANALYSIS ==========")
print("1. Department-wise Employee Count (Bar Graph)")
print("2. Average Salary by Department (Bar Graph)")
print("3. Salary vs Experience (Bar Graph)")
print("4. Department-wise Employee Percentage (Pie Chart)")
print("5. Exit")
print("6. Total Salary Expenditure by Department (Bar Graph)")
print("8. Salary to Experience Ratio (Line Chart)")
print("9. Salary vs Age (Bar Graph)")
plt.clf()
choice = input("\nEnter your choice (1-9): ")
if choice == '1':
dept_count = df['Department'].value_counts()
dept_count.plot(kind='bar', color='skyblue', edgecolor='black')
plt.title('Department-wise Employee Count')
plt.xlabel('Department')
plt.ylabel('Number of Employees')
plt.show()
elif choice == '2':
avg_salary = df.groupby('Department')['Salary'].mean()
avg_salary.plot(kind='bar', color='lightgreen', edgecolor='black')
plt.title('Average Salary by Department')
plt.xlabel('Department')
plt.ylabel('Average Salary')
plt.show()
elif choice == '3':
df.plot(kind='bar', x='Experience', y='Salary', color='lightblue', edgecolor='black')
plt.title('Salary by Experience')
plt.xlabel('Experience (Years)')
plt.ylabel('Salary')
plt.show()
elif choice == '4':
dept_count = df['Department'].value_counts()
dept_count.plot(kind='pie', autopct='%1.1f%%', startangle=90, shadow=True)
plt.title('Department-wise Employee Percentage')
plt.ylabel('')
plt.show()
elif choice == '5':
print("Exiting program...")
break
elif choice == '6':
total_salary = df.groupby('Department')['Salary'].sum()
total_salary.plot(kind='bar', color='orange', edgecolor='black')
plt.title('Total Salary Expenditure by Department')
plt.xlabel('Department')
plt.ylabel('Total Salary')
plt.tight_layout()
plt.show()
elif choice == '8':
ratio_df = df.groupby('Experience')['Salary'].mean()
plt.plot(ratio_df.index, ratio_df.values, marker='o', linestyle='-', color='purple')
plt.title('Salary to Experience Ratio')
plt.xlabel('Experience (Years)')
plt.ylabel('Average Salary')
plt.grid(True)
plt.tight_layout()
plt.show()
elif choice == '9':
df.plot(kind='bar', x='Age', y='Salary', color='salmon', edgecolor='black')
plt.title('Salary by Age')
plt.xlabel('Age')
plt.ylabel('Salary')
plt.show()
else:
print("Invalid choice! Please enter a valid option (1-9).")