0% found this document useful (0 votes)
2 views

PDA_Assignment questions

The document outlines five assignments involving various programming tasks in Python. Assignments cover operations on lists, dictionary manipulation for student data, NumPy arithmetic operations, data handling with pandas, and managing missing data in a dataset. Each assignment includes specific instructions and examples to guide the implementation.

Uploaded by

S.Y Suprabhath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

PDA_Assignment questions

The document outlines five assignments involving various programming tasks in Python. Assignments cover operations on lists, dictionary manipulation for student data, NumPy arithmetic operations, data handling with pandas, and managing missing data in a dataset. Each assignment includes specific instructions and examples to guide the implementation.

Uploaded by

S.Y Suprabhath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment 1: Perform various operations on a larger list of values.

Instructions:

Given the list of values: [12, 34, 56, 78, 90, 23, 45, 67, 89, 101], perform the following tasks:

1. Print the Original List:


• Display the list as it is.
2. Append Multiple Elements:
• Append the values 202, 303, and 404 to the end of the list.
• Print the list after appending these values.
3. Insert Elements:
• Insert the value 15 at index 5.
• Insert the value 25 at index 2.
• Print the list after each insertion.
4. Remove an Element:
• Remove the value 67 from the list.
• Print the list after removing the value.
5. Reverse the List:
• Reverse the order of elements in the list.
• Print the reversed list.
6. Indexing:
• Print the element at index 7 of the list.
7. Slicing:
• Print a slice of the list from index 4 to 8
• Print a slice of the list from the beginning to index 5
• Print a slice of the list with every third element
8. Find the Index of an Element:
• Find and print the index of the value 90 in the list.

Assignment 2 :

You are tasked with building a dictionary-based data system for an educational institution. The institution
offers various courses, and students are enrolled in these courses. Your job is to create, manipulate, and
access various pieces of information using Python dictionaries.

Instructions:

1. Initialize an empty dictionary to store student information.

• The dictionary will store data about students using their student ID as the key.
Each student will have a dictionary as the value, which contains their name, age, and a
list of courses they are enrolled in.

2. Add student information to the dictionary using the following data:

• Student 1: ID: 101, Name: "Aarav", Age: 20, Courses: ['AIML', 'Data
Structures']
• Student 2: ID: 102, Name: "Ishita", Age: 22, Courses: ['NHCE', 'Discrete Math',
'Algorithms']
• Student 3: ID: 103, Name: "Rahul", Age: 21, Courses: ['AI Ethics', 'New
Horizon', 'Databases']

3. Add new courses to Student 1 and Student 3:

• Add 'Python Programming' to Aarav's courses.


• Add 'Machine Learning' to Rahul's courses.

4. Create a nested structure within the dictionary for each student:


• Add a grade dictionary for each student that stores their grades for each course
they are enrolled in. The grades will be stored as a dictionary within the student
dictionary, where the course name is the key, and the grade (e.g., 'A', 'B+', 'C') is the
value.
For example:
python
Copy code
students[101]['grades'] = {'AIML': 'A', 'Data Structures': 'B+'}
• Initialize grades for all courses for each student.

5. Access the following data from the dictionary:


• Retrieve and print Ishita's age.
• Print Rahul's grades for his enrolled courses.
• Print all courses that Aarav is enrolled in.

6. Update student information:

• Update Ishita's age to 23.


• Update Rahul’s grade for "Databases" to 'A+'.

7. Remove a course:

• Remove 'Discrete Math' from Ishita's list of courses, and delete the
corresponding grade entry.
8. Print all students and their data:

• Write a loop to print all student information in a readable format, including their
ID, name, age, courses, and grades.

Assignment 3:

1: NumPy Arithmetic Operations


1. Create a 2x2 NumPy array, arr1, using np.arange() and ensure the values are of float type.
2. Create another 1D array, arr2, with two elements [5, 10].
3. Perform the following operations between arr1 and arr2 and print the results:
o Addition
o Subtraction
o Multiplication
o Division
2: Reading and Writing CSV with pandas
1. Create a pandas DataFrame called scores_df with two columns:
o Name: A list of 5 student names of your choice.
o Score: Corresponding scores (between 0 and 100) for each student.
2. Save the DataFrame as a CSV file named students.csv in the following formats:
o Save with both columns.
o Save another version with only the Name column.
3: Reading a CSV
1. Read the students.csv file you saved earlier and display the first 3 rows of the DataFrame using
pandas.
4: Data Manipulation
1. In the DataFrame from Task 2, increase every student's score by 10 points. If the new score
exceeds 100, set it to 100.
2. Save the updated DataFrame back to a new CSV file named updated_students.csv.

Assignment-4

1. Write a Python program to create a Pandas DataFrame from a larger list of dictionaries containing
information such as name, age, score, and city. Perform basic operations like selecting specific columns
and filtering rows based on conditions.
2. Write a Python program to plot a line chart and a scatter plot using Matplotlib to visualize the age and
score data.
data_india = [
{'Name': 'Aarav', 'Age': 20, 'Score': 85, 'City': 'Mumbai'},
{'Name': 'Vivaan', 'Age': 21, 'Score': 90, 'City': 'Delhi'},
{'Name': 'Aditya', 'Age': 19, 'Score': 95, 'City': 'Bengaluru'},
{'Name': 'Vihaan', 'Age': 18, 'Score': 80, 'City': 'Chennai'},
{'Name': 'Reyansh', 'Age': 22, 'Score': 88, 'City': 'Hyderabad'},
{'Name': 'Krishna', 'Age': 23, 'Score': 93, 'City': 'Ahmedabad'},
{'Name': 'Shivansh', 'Age': 24, 'Score': 78, 'City': 'Kolkata'},
{'Name': 'Ayaan', 'Age': 25, 'Score': 85, 'City': 'Pune'},
{'Name': 'Kabir', 'Age': 21, 'Score': 91, 'City': 'Jaipur'},
{'Name': 'Arjun', 'Age': 20, 'Score': 87, 'City': 'Lucknow'},
]

Assignment 5: Handling Missing Data and Understanding Variability Using NumPy and Pandas

You are given a dataset that represents the ages of participants in a survey. However, some data points are
missing. Your task is to handle the missing data, then calculate the mean, variance, and standard
deviation to understand how much the ages differ from the average age.
Instructions:

1. Create a Python program that:


o Stores the given list of ages in a Pandas DataFrame.
o Uses the isnull() function to identify the missing values in the dataset.
o Replaces the missing values with the mean of the non-missing values.
o Calculates the mean of the complete list (after handling missing values).
o Calculates the variance using the np.var() function.
o Calculates the standard deviation using the np.std() function.
2. Write code comments explaining each step.
3. After calculating these values, answer the following questions:
o What does the variance tell you about the spread of the ages?
o What does the standard deviation indicate about the consistency of the ages in the
dataset?

Example Data (with missing values):

ages = [23, 29, np.nan, 35, 22, 26, np.nan, 30, 32, 34]

You might also like