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

Python Practical List 24

Ip project class 12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Python Practical List 24

Ip project class 12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Practical file Questions2020-2021

2024-25

Python Pandas
1. Write a Pandas program to create and display a DataFrame from a specified dictionary data
which has the index labels.
Sample DataFrame:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew',
'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
2. Write a Pandas program to get the first 3 rows of a given DataFrame.
Sample DataFrame:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew',
'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
3. Write a Pandas program to select the 'name' and 'score' columns from the following DataFrame.

Sample DataFrame:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew',
'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
4. Write a Pandas program to select the specified columns and rows from a given DataFrame.
Select 'name' and 'score' columns in rows 1, 3, 5, 6 from the following data frame.

Sample DataFrame:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew',
'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
5. Write a Pandas program to change the score in row 'd' to 11.5.

Sample DataFrame:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew',
'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
6. Write a Pandas program to add, subtract, multiple and divide two Pandas Series.
Sample Series: [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]
7. Write a Pandas program to compare the elements of the two Pandas Series.
Sample Series: [2, 4, 6, 8, 10], [1, 3, 5, 7, 10]
8. Write a Pandas program to calculate the frequency counts of each unique value of a given series.

Matplotlib Basic
9. Write a Python program to draw a line using given axis values with suitable label in the x axis , y
axis and a title
The code snippet gives the output shown in the following screenshot:
10. Write a Python program to plot two or more lines with different styles. The code snippet gives
the output shown in the following screenshot:

11. Write a Python programming to display a bar chart of the popularity of programming Languages.
Sample data:
Programming languages: Java, Python, PHP, JavaScript, C#, C++
Popularity: 22.2, 17.6, 8.8, 8, 7.7, 6.7
The code snippet gives the output shown in the following screenshot:

12. Write a Python program to create bar plot of scores by group and gender. Use multiple X values
on the same chart for men and women.
Sample Data:
Means (men) = (22, 30, 35, 35, 26)
Means (women) = (25, 32, 30, 35, 29)
The code snippet gives the output shown in the following screenshot:
13. Write a Python program to create bar plot from a DataFrame.
Sample Data Frame:
abcde
2 4,8,5,7,6
4 2,3,4,2,6
6 4,7,4,7,8
8 2,6,4,8,6
10 2,4,3,3,2
The code snippet gives the output shown in the following screenshot:

MYSQL
Index for SQL
Consider the tables given below and answer the questions that follow:
Table: Employee
No Name Salary Zone Age Grade Dept
1 Mukul 30000 West 28 A 10
2 Kritika 35000 Centre 30 A 10 Table: Department
3 Naveen 32000 West 40 NULL 20 Dept DName MinSal MaxSal HOD
4 Uday 38000 North 38 C 30 10 Sales 25000 32000 1
5 Nupur 32000 East 26 NULL 20 20 Finance 30000 50000 5
6 Moksh 37000 South 28 B 10 30 Admin 25000 40000 7
7 Shelly 36000 North 26 A 30
Write SQL commands to:
Create Table
1. Create the table Employee.
2. Create the table Department.
Insert data in a table
3. Insert data in the table Employee
4. Insert data in the table Department.
Simple Select
5. Display the Salary, Zone, and Grade of all the employees.
6. Display the name of all the employees along with their annual salaries. The Salary
column of the table contains monthly salaries of the employees. The new column
should be given the name “Annual Salary”.
Conditional Select using Where Clause
7. Display the details of all the employees who are below 30 years of age.
Using DISTINCT Clause
8. Display the names of various zones from the table Employee. A zone name should
appear only once.
Using Logical Operators (NOT, AND, OR)
9. Display the details of all the employees who are getting a salary of more than 35000
in the department 30.
10. Display the names and salaries of all the employees who are not working in
department 20.
11. Display the details of all the employees whose salary is between 32000 and 38000.
Using IN Operator
12. Display the names of all the employees who are working in department 20 or 30.
(Using IN operator)
Using BETWEEN Operator
13. Display the details of all the employees whose salary is between 32000 and 38000.
14. Display the details of all the employees whose grade is between ‘A’ and ‘C’.
Using LIKE Operator
15. Display the name, salary, and age of all the employees whose names start with ‘M’.
16. Display the name, salary, and age of all the employees whose names contain ‘a’ in
the descending order of their names.
17. Display the details of all the employees whose names contain ‘a’ as the second
character.
Using Aggregate functions
18. Display the highest and the lowest salaries being paid in department 10.
19. Display the number of employees working in department 10.
Using ORDER BY clause
20. Display the name and salary of all the employees in the ascending order of their
salaries.
Using GROUP BY clause
21. Display the total number of employees in each department.
22. Display the highest salary, lowest salary, and average salary of each zone.
Using UPDATE, DELETE, ALTER TABLE
23. Put the grade B for all those whose grade is NULL.
24. Increase the salary of all the employees above 30 years of age by 10%.
25. Delete the records of all the employees whose grade is C and salary is below 30000.
26. Add another column HireDate of type Date in the Employee table.

Python and Mysql Connection(do not write in practical note book.)

1. Write a Python program to list the tables of given MySQL database file.
2. Write a Python program to create a table and insert some records in that table. Finally selects all
rows from the table and display the records
3. Write a Python program to insert a list of records into a given MySQL table.
4. Write a Python program to insert values to a table from user input.
5. Write a Python program to count the number of rows of a given MySQL table.
6. Write a Python program to update a specific column value of a given table and select all rows
before and after updating the said table.
7. Write a Python program to update all the values of a specific column of a given MySQL table.
8. Write a Python program to delete a specific row from a given MySQL table.
9. Write a Python program to alter a given MySQL table.

You might also like