Skip to main content

Posts

CSV SAMPLE PROJECT | MENU DRIVEN | 14 AUG

  # -*- coding: utf-8 -*- """ Created on Thu Aug 14 13:21:08 2025 @author: Kirti Hora """ import csv def createcsv():     filename = "emp.csv"     with open(filename, "w", newline="") as csv_fobj:         wtr_obj = csv.writer(csv_fobj)         wtr_obj.writerow(["Empno", "Name", "Basic Salary", "Allowance", "Deduction", "Net Salary"])         while True:             eno = input("Enter employee no: ")             name = input("Enter name: ")             bs = float(input("Enter basic salary: "))             allowance = 2000             dedn = bs * 0.05             net = bs + allowance - dedn             wtr_obj.writerow([eno, name, bs, allowance, dedn, net])             ...
Recent posts

GRADE XII - CSV FILE

CSV FILE (COMMA SEPERATED VALUE) Writing data to a CSV file involves the following steps: Import the csv module Open the CSV file in write mode ( "w" ) using open() Create the writer object Write the data into the file using the writer object Close the file using close() writerow() Method This method is used to write a single row to a CSV file. It takes a sequence (list or tuple) as its parameter, and writes the items as a comma-separated line in the file. You do not need to add a newline character (\n) — it automatically places the end-of-line marker.     EXAMPLE 1: import csv  # Importing the csv module # CSV file opened using relative path csv_fobj = open("emp.csv", "w")   # Writer object created wtr_obj = csv.writer(csv_fobj) # Record with field heading is written wtr_obj.writerow(["Empno", "Name", "Salary"]) # Records with data are written wtr_obj.writerow([1, "Akash...

GRADE XII - Binary File Manipulation (Dictionary)

  Binary File Manipulation (Dictionary) import pickle from os import remove, rename   def Create():     with open("emp.dat", "wb") as File:         while True:             Eno = int(input("Eno: "))             Name = input("Name: ")             Sal = float(input("Salary: "))             Dept = input("Department: ")             Emp = {"Eno": Eno, "Name": Name, "Sal": Sal, "Dept": Dept}             pickle.dump(Emp, File)             Ans = input("More (Y/N)? ")           ...

DATAFRAME IMP QUESTIONS

  Q30. Consider the following CORONA DataFrame and answer the questions given below: ID State Cases 100 Delhi 3000 110 Mumbai 4000 120 Chennai 5000 130 Surat 4500 Create the above dictionary and DataFrame with given data and perform the following operations: (a) Write code to add a new column named 'Recovery' using the Series method. This column should store the number of patients recovered in each state. (Assume appropriate values) (b) Add a new column named 'Deaths' using the assign() method to store the number of deaths in each state. (Assume values) (c) Add a new row using loc[] to store details of another state. (Assume values) (d) Add a new column named 'Percentage' using the insert() method. This column should store the percentage of recovery in each state and must...