0% found this document useful (0 votes)
25 views3 pages

Coding 2

This document outlines a Python program for managing employee salaries at CSKM Public School. It allows users to add, update, delete, and view employee records, as well as generate charts based on salary data. The program utilizes the pandas library for data manipulation and matplotlib for visualizations.

Uploaded by

Divyanshu Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Coding 2

This document outlines a Python program for managing employee salaries at CSKM Public School. It allows users to add, update, delete, and view employee records, as well as generate charts based on salary data. The program utilizes the pandas library for data manipulation and matplotlib for visualizations.

Uploaded by

Divyanshu Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

import pandas as pd

import matplotlib.pyplot as plt

print('===============CSKM Public School================')


print('= =')
print('= Welcome to Employee Salary Module =')
print('= =')
print('=================================================')
dfemp = pd.read_csv('empsal.csv',
header=None,
names=['empno','name','department','salary'])
choice = 0
while(choice != 6):
print('Choices for the module')
print('1. Add a new employee')
print('2. Update Emplpyee')
print('3. Delete Employee')
print('4. View Employees')
print('5. View Charts')
print('6. Exit')
choice = int(input('Enter your choice : '))

if(choice == 1):
empno = int(input('Input Employee Number : '))
ename = input('Input Employee Name : ')
dept = input('Input Department : ')
salary = input('Input Salary : ')
noofemployee = len(dfemp)
dfemp.loc[noofemployee] = [empno,ename,dept,salary]
print(dfemp)
dfemp.to_csv('empsal.csv',header=False,index=False)
elif (choice == 2):
empno = int(input('Enter Employee Number : '))
print(dfemp.loc[dfemp['empno'] == empno])
indexno = dfemp.loc[dfemp['empno'] == empno].index
print('1. Update Employee Number')
print('2. Update Name')
print('3. Update Department')
print('4. Update Salary')
updatechoice = int(input('Enter your choice for update : '))
if (updatechoice == 1):
newempno = int(input('Enter new employee number : '))
dfemp.loc[indexno,'empno'] = newempno
dfemp.to_csv('empsal.csv',header=False,index=False)
elif (updatechoice == 2):
newempname = input('Enter new employee Name : ')
dfemp.loc[indexno,'name'] = newempname
dfemp.to_csv('empsal.csv',header=False,index=False)
elif (updatechoice == 3):
newempdept = input('Enter new employee Department : ')
dfemp.loc[indexno,'department'] = newempdept
dfemp.to_csv('empsal.csv',header=False,index=False)
elif (updatechoice == 4):
newempsal = input('Enter new employee Salary : ')
dfemp.loc[indexno,'salary'] = newempsal
dfemp.to_csv('empsal.csv',header=False,index=False)
print(dfemp.loc[dfemp['empno'] == empno])
print('----Employee Record Updated----')

elif (choice == 3):


empno = int(input('Enter Employee Number : '))
print(dfemp.loc[dfemp['empno'] == empno])
indexno = dfemp.loc[dfemp['empno'] == empno].index
confirm = input('Are you sure you want to delete it (Y/N) : ')
if (confirm == 'Y' or confirm == 'y'):
dfemp = dfemp.drop(indexno)
dfemp.to_csv('empsal.csv',header=False,index=False)
print('---------- Record Deleted ---------')

elif (choice == 4):


print('1. Display all ')
print('2. Display top ___ records')
print('3. Display bottom ___ records')
print('4. Display on the basis of department')
dispchoice = int(input('Enter your choice'))
if (dispchoice == 1):
print(dfemp)
elif (dispchoice == 2):
top = int(input('Enter how many top records to be displayed : '))
print(dfemp.head(top))
elif (dispchoice == 3):
bottom = int(input('Enter how many bottom records to be displayed : '))
print(dfemp.tail(bottom))
elif (dispchoice == 4):
dept = input('Enter Department Name : ')
print(dfemp.loc[dfemp['department'] == dept])
elif (choice == 5):
print('1. Bar Chart - Department wise salary')
print('2. Department Wise Total Salary - Line Chart')
print('3. Department Wise Average Salary - Line Chart')
print('4. Back Menu')
chartchoice = int(input('Enter your choice : '))
if (chartchoice == 1):
dftemp = dfemp.groupby ('department').aggregate('sum')
depts = dftemp.index.to_list()
salarysum = dftemp['salary']
plt.bar(depts,salarysum)
plt.xlabel('Departments')
plt.ylabel('Salary')
plt.title('Department Wise Total Salary')
plt.show()
elif (chartchoice == 2):
dftemp = dfemp.groupby ('department').aggregate('sum')
depts = dftemp.index.to_list()
salarysum = dftemp['salary']
plt.plot(depts,salarysum)
plt.xlabel('Departments')
plt.ylabel('Salary')
plt.title('Department Wise Total Salary')
plt.show()
elif (chartchoice == 3):
dftemp = dfemp.groupby ('department').aggregate('mean')
depts = dftemp.index.to_list()
salarysum = dftemp['salary']
plt.plot(depts,salarysum)
plt.xlabel('Departments')
plt.ylabel('Salary')
plt.title('Department Wise Average Salary')
plt.show()

You might also like