Computer Science, asked by cvinay729, 2 months ago

Write a menu driven python program to perform following using csv file named as “Employee.csv” .

Attachments:

Answers

Answered by prachi4881
1

Answer:

human readable text file where each line has a number of fields & separated by commas.

Answered by chandujnv002
0

Answer:

Here's a sample code for a menu-driven Python program that performs the following operations using a CSV file named "Employee.csv". You need to have the "pandas" module installed to run this program:

import pandas as pd

# function to add employee record to CSV file

def add_employee():

   # get input from user

   emp_name = input("Enter employee name: ")

   emp_code = input("Enter employee code: ")

   emp_salary = input("Enter employee salary: ")

   designation = input("Enter employee designation: ")

   doj = input("Enter date of joining (dd/mm/yyyy): ")

   

   # add record to CSV file

   with open("Employee.csv", "a") as file:

       file.write(f"{emp_name},{emp_code},{emp_salary},{designation},{doj}\n")

       

   print("Employee record added successfully.")

# function to display employee record by Empcode

def display_employee_by_code():

   # get input from user

   emp_code = input("Enter employee code to search: ")

   

   # read CSV file and search for employee record

   df = pd.read_csv("Employee.csv", header=None)

   result = df[df[1] == emp_code]

   

   # display result

   if len(result) > 0:

       print(result)

   else:

       print("Employee not found.")

# function to display all employee records

def display_all_employees():

   # read CSV file and display all records

   df = pd.read_csv("Employee.csv", header=None)

   print(df)

# main function to run the program

def main():

   while True:

       print("\nMENU:")

       print("1. Add employee record")

       print("2. Display employee record by Empcode")

       print("3. Display all employee records")

       print("4. Exit")

       choice = input("Enter your choice (1-4): ")

       

       if choice == "1":

           add_employee()

       elif choice == "2":

           display_employee_by_code()

       elif choice == "3":

           display_all_employees()

       elif choice == "4":

           break

       else:

           print("Invalid choice. Try again.")

if __name__ == "__main__":

   main()

This program uses the "pandas" module to read and write data to a CSV file. The program has three functions to add an employee record, display an employee record by Empcode, and display all employee records. The main function presents a menu to the user and calls the appropriate function based on the user's choice.

To learn more about data from the link below

https://brainly.in/question/28198596

To learn more about Python program from the link below

https://brainly.in/question/49222417

#SPJ2

Similar questions