You are on page 1of 37

Index

Pr. Practical’s Name / Description Page.


No. No.
1. Write a program to create a Series object using a dictionary that stores the number
of students in each section of class 12 in your class.

2. Write a program to create a Series object using individual vowel characters.

3. Write a program to create a Series object using an ndarray that is created by tiling a
list [1,2,3]. Use np.tile() methods.

4. Sequences section and contri1 stores the section names (‘A’, ‘B’, ‘C’, ‘D’) and
contribution made by them respectively (6700, 5600, 5000, nil) for a charity. Your
school has decided to donate as much contribution as made by each section, i.e. the
donation will be doubled.

Write code to create a Series object that stores the contribution amount as the values
and the section names as the indexes with datatype as float32.

5. Write a program to create a Series object that stores the initial budget allocated
(5000.00 each) for the four quarters of the year.

6. Write Python program to Create a DataFrame with the help of dictionary, which
contains the information about Marks of Five students of five subjects.
Dictionary Contains – [Write commands to create dictionary also]
Name Maths Sc SSc Hindi Total
Aditya 85 95 80 70 330
Saloni 95 100 100 99 394
Muskan 88 99 99 99 385
Tamanna 99 88 99 98 384

7. Write python code to create a data frame from a 2D dictionary, Sales which stores
the quarter-wise sales as inner dictionary for two years, as shown below :
Sales = {‘yr1’ : {‘q1’ : 34000, ‘q2’ : 56000, ‘q3’: 85000},
‘yr2’ : {‘q1’ : 44000, ‘q2’ : 66000, ‘q3’: 55000} }

8. Write a program to create a DataFrame from a list containing dictionaries of the sales
performance of four zonal offices. Zone names should be the row labels.
9. Write a program to create a DataFrame to store weight, age and name of 3 people.
Print the DataFrame and its index, columns, axes, dtypes, number of rows, number
of non-NaN values in each column, and transpose of data frame. [Attributes of
DataFrame]

10. Consider the following DataFrame saleDF:-

Python 2 MySQL
Target Sales
zoneA 56000 58000
zoneB 70000 68000
zoneC 75000 78000
zoneD 60000 61000

Write a program to add a column namely Orders having values 6000, 6700, 6200,
and 6000 respectively for the zones A, B, C and D. The program should also add a
new row for a for a new zone ZoneE. Add some dummy values in this row.
11. Create a DataFrame cityStat having following information –
Population Hospitals Schools
Delhi 10927986.0 189.0 7916.0
Mumbai 12691836.0 208.0 8508.0
Kolkata 4631392.0 149.0 7226.0
Chennai 4328063.0 157.0 7617.0
Bangalore 5678097.0 1200.0 1200.0

From the above DataFrame cityStat, create another DataFrame and it must not
contain the column ‘Population’ and the row ‘Banglore’
12. Write a program to read from a CSV file employee.csv and create a dataframe from
it, but dataframe should not use file’s column header rather should use own column
numbers as 0, 1, 2, ……

13. Write a program to store the allDf DataFrame of previous example in fill alln.csv
with separator character ‘|’

14. The student table of test database of MySQL stores student details as RollNO, Name,
Marks, Grade.
Write a program to load only rows of this Student table where marks > 70 in a
dataframe namely mdf.

15. Naman is doing some research. He has a stored line of Pascal's triangle numbers as
ar2 as show below: -
ar2 = [1, 7, 21, 35, 35, 21, 7, 1]
 He wants to plot the sine (use numpy.sin() ) , cosine (use numpy.cos()) and
tangent values (use numpy.tan() ) for the same array ar2.
 He wants cyan color for sine plot line, red color for cosine plot line, and the
black color for tangent plot line.
 Also, the tangent line should be dashed.
16. Write a program to plot a scatter graph taking two random distributions in X1 and
Y1 (both with shape as (250,) having randomly generated integers) and plotted
against each other with varying sizes and varying colors.
17. Write a program to plat a bar chart from the marks scored by you and your friends
in different subjects.

Python 3 MySQL
18. DPS school celebrated volunteering week where each section of class XI dedicated
a day for collecting amount for charity being supported by the school. Section A
volunteered on Monday, B on Tuesday, C on Wednesday and so on. There are six
sections in Class XI. Amounts collected by sections A to F are 8000, 12000, 9800,
11200, 15500, 7300
Draw a bar chart to show the collection of amounts graphically.
19. A survey gathers hegith and weight of 100 participants and recorded the
participant's ages :-
ages = [1, 1 , 2 , 3 , 5 , 7 , 8 , 9 , 10 , 10, 11, 13, 13, 15, 16, 17, 18, 19, 20, 21, 21, 23,
24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 27, 27, 27, 27, 27, 29, 30, 30, 30, 30, 31, 33,
34, 34, 34, 35, 36, 36, 37, 37, 37, 38, 38, 39, 40, 40, 41, 41, 42, 43, 45, 45, 46, 46,
46, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 54, 55, 56, 57, 58, 60, 61, 63, 65, 66, 68,
70, 72, 74, 75, 77, 81, 83, 84, 87, 89, 90, 91]
Write a program to plat a histogram from above data with 20 bins.

20. Consider a DataFrame mksdf as shown below:


Name Age PreBoardMarks BoardMarks
0 Karan 17 4 25
1 Alex 19 24 94
2 Ani 18 31 57
3 Javed 18 2 62
4 Amrit 17 3 70

Write a program to plot pre-board-marks and board marks from above DataFrame
on the same line chart

21. MySQL Queries


1. Write a SQL command to create a Database named ‘School’. Also write the command
to
2. Create a student table with the student id, name, and marks as attributes where the
student id is the primary key.
3. Add columns ‘Mobile’ and ‘Sex’ in the table student.
4. Add column ‘Address’ in the table student.
5. Change the name of column ‘Sex’ to ‘Gender’
6. Delete a column ‘Address’ from table Student.
7. Insert the details of 10 new students in the above table.
8. Use the select command to get the details of the students with marks more than 80.
9. Change the mobile number of any one student.
10. Display the details of those students which name start with ‘A’
11. Write output : SELECT LENGTH(NAME), SUBSTR(NAME, 3,3) FROM STUDENT;
12. Write output : SELECT COUNT (DISTINCT GENDER) FROM STUDENT;
13. Display a report like ‘Aditya is scored 20 out of 30” for each student. Where Aditya is
the name of student and 20 is the marks of Aditya.
14. Find the min, max, sum, and average of the marks in a student marks table.
15. Display the Gender, Minimum marks and Maximum Marks Gender wise.
16. Find the total number of students from student table gender wise using group by.

Python 4 MySQL
17. Write a SQL query to order the (student ID, marks) table in descending order of the
marks.
18. Delete the details of a student in the above table.
19. Delete the table Student.
20. Delete the Database School.

Python 5 MySQL
-: Question – 1 :-
Write a program to create a Series object using a dictionary that stores the number of students in
each section of class 12 in your class.
Code: -

Output: -

Python 6 MySQL
-: Question – 2 :-
Write a program to create a Series object using individual vowel characters.
Code: -

Output: -

Python 7 MySQL
-: Question – 3 :-
Write a program to create a Series object using an ndarray that is created by tiling a list [1,2,3]. Use
np.tile() methods.
Code: -

Output: -

Python 8 MySQL
-: Question – 4 :-
Sequences section and contri1 stores the section names (‘A’, ‘B’, ‘C’, ‘D’, ‘E’) and contribution made
by them respectively (6700, 5600, 5000, nil) for a charity. Your school has decided to donate as much
contribution as made by each section, i.e. the donation will be doubled.
Write code to create a Series object that stores the contribution amount as the values and the section
names as the indexes with datatype as float32.
Code: -

Output: -

Python 9 MySQL
-: Question – 5 :-
Write a program to create a Series object that stores the initial budget allocated (5000.00 each) for
the four quarters of the year.
Code: -

Output: -

Python 10 MySQL
-: Question – 6 :-
Write Python program to Create a DataFrame with the help of dictionary, which contains the
information about Marks of Five students of five subjects.

Dictionary Contains – [Write commands to create dictionary also]

Name Maths Sc SSc Hindi Total


Aditya 85 95 80 70 330
Saloni 95 100 100 99 394
Muskan 88 99 99 99 385
Tamanna 99 88 99 98 384
Code: -

Output: -

Python 11 MySQL
-: Question – 7 :-
Write python code to create a data frame from a 2D dictionary, Sales which stores the quarter-wise
sales as inner dictionary for two years, as shown below :
Sales = {‘yr1’ : {‘q1’ : 34000, ‘q2’ : 56000, ‘q3’: 85000},
‘yr2’ : {‘q1’ : 44000, ‘q2’ : 66000, ‘q3’: 55000} }
Code: -

Output: -

Python 12 MySQL
Question – 8
Write a program to create a data frame from a list containing dictionaries of the sales performance
of four zonal offices. Zone names should be the row labels.
Code: -

Output: -

Python 13 MySQL
Question – 9
Write a program to create a DataFrame to store weight, age and name of 3 people. Print the
DataFrame and its index, columns, axes, dtypes, number of rows, number of non-NaN values in each
column, and transpose of data frame. [Attributes of DataFrame]
Code: -

Output: -

Python 14 MySQL
Python 15 MySQL
Question - 10
Consider the following DataFrame saleDF:-
Target Sales
zoneA 56000 58000
zoneB 70000 68000
zoneC 75000 78000
zoneD 60000 61000

Write a program to add a column namely Orders having values 6000, 6700, 6200, and 6000
respectively for the zones A, B, C and D. The program should also add a new row for a for a new
zone ZoneE. Add some dummy values in this row.

Code: -

Python 16 MySQL
Output: -

Python 17 MySQL
Question – 11
Create a DataFrame cityStat having following information –
Population Hospitals Schools
Delhi 10927986.0 189.0 7916.0
Mumbai 12691836.0 208.0 8508.0
Kolkata 4631392.0 149.0 7226.0
Chennai 4328063.0 157.0 7617.0
Bangalore 5678097.0 1200.0 1200.0

From the above DataFrame cityStat, create another DataFrame and it must not contain the column
‘Population’ and the row ‘Banglore’
Code: -

Output: -

Python 18 MySQL
Question – 12
Write a program to read from a CSV file employee.csv and create a dataframe from it, but dataframe
should not use file’s column header rather should use own column numbers as 0, 1, 2, ……
Code: -

CSV File :-

Output: -

Python 19 MySQL
Question - 13
Write a program to store the allDf DataFrame of previous example in fill alln.csv with separator
character ‘|’
Code: -

Output (CSV File): -

Python 20 MySQL
Question – 14
The student table of test database of MySQL stores student details as RollNO, Name, Marks, Grade.
Write a program to load only rows of this Student table where marks > 80 in a dataframe namely mdf.
Code: -

Output: -

Python 21 MySQL
Question – 15
Naman is doing some research. He has a stored line of Pascal's triangle numbers as ar2 as show
below:-
ar2 = [1, 7, 21, 35, 35, 21, 7, 1]
 He wants to plot the sine (use numpy.sin() ) , cosine (use numpy.cos()) and tangent values
(use numpy.tan() ) for the same array ar2.
 He wants cyan color for sine plot line, red color for cosine plot line, and the black color for
tangent plot line.
Also, the tangent line should be dashed.
Solution
import matplotlib.pyplot as plt
import numpy as np
ar2 = [1, 7, 21, 35, 35, 21, 7, 1]
si = np.sin(ar2)
co = np.cos(ar2)
ta = np.tan(ar2)
plt.plot(ar2, si, 'c', label = 'sin')
plt.plot(ar2, co, 'r', label = 'cos')
plt.plot(ar2, ta, 'k', ls = 'dashed', label = 'tan')
plt.legend(loc = 1)
plt.show()
Output

Python 22 MySQL
Question – 16
Write a program to plot a scatter graph taking two random distributions in X1 and Y1 (both with
shape as (250,) having randomly generated integers) and plotted against each other with varying
sizes and varying colors.
Code: -

Output: -

Python 23 MySQL
Question – 17
Write a program to plat a bar chart from the marks scored by you and your friends in different
subjects
Code: -

Output: -

Python 24 MySQL
Python 25 MySQL
Question – 18
DPS school celebrated volunteering week where each section of class XI dedicated a day for
collecting amount for charity being supported by the school. Section A volunteered on Monday, B
on Tuesday, C on Wednesday and so on. There are six sections in Class XI. Amounts collected by
sections A to F are 8000, 12000, 9800, 11200, 15500, 7300
Code: -

Output: -

Python 26 MySQL
Question – 19
A survey gathers hegith and weight of 100 participants and recorded the participant's ages:-
ages = [1, 1, 2 , 3 , 5 , 7 , 8 , 9 , 10 , 10, 11, 13, 13, 15, 16, 17, 18, 19, 20, 21, 21, 23, 24, 24, 24, 25,
25, 25, 25, 26, 26, 26, 27, 27, 27, 27, 27, 29, 30, 30, 30, 30, 31, 33, 34, 34, 34, 35, 36, 36, 37, 37, 37,
38, 38, 39, 40, 40, 41, 41, 42, 43, 45, 45, 46, 46, 46, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 54, 55, 56,
57, 58, 60, 61, 63, 65, 66, 68, 70, 72, 74, 75, 77, 81, 83, 84, 87, 89, 90, 91]
Write a program to plat a histogram from above data with 20 bins
Code :-

Output :-

Python 27 MySQL
Python 28 MySQL
Question – 20
Consider a DataFrame mksdf as shown below:
Name Age PreBoardMarks BoardMarks
0 Karan 17 4 25
1 Alex 19 24 94
2 Ani 18 31 57
3 Javed 18 2 62
4 Amrit 17 3 70

Write a program to plot pre-board-marks and board marks from above DataFrame on the same
scatter chart.
Code: -

Python 29 MySQL
Output: -

Python 30 MySQL
Question – 21

MySQL Queries (20)


*Write a SQL command to create a Database named ‘School’. Also write the command to Create a student
table with the student id, name, and marks as attributes where the student id is the primary key.

*Add columns ‘Mobile’ and ‘Sex’ in the table student.

*Add column ‘Address’ in the table student

Python 31 MySQL
*Change the name of column ‘Sex’ to ‘Gender’

*Delete a column ‘Address’ from table Student

Python 32 MySQL
*Insert the details of 10 new students in the above table.

Python 33 MySQL
*Change the mobile number of any one student

*Display the details of those students which name start with ‘A’

*Write output : SELECT LENGTH(NAME), SUBSTR(NAME, 3,3) FROM STUDENT;

Python 34 MySQL
*Write output : SELECT COUNT (DISTINCT GENDER) FROM STUDENT;

*Find the min, max, sum, and average of the marks in a student marks table

Python 35 MySQL
*Display the Gender, Minimum marks and Maximum Marks Gender wise.

Python 36 MySQL
*Write a SQL query to order the (student ID, marks) table in descending order of the marks.

*Delete the details of a student in the above table.

*Delete the table Student.

Python 37 MySQL
*Delete the Database School.

Python 38 MySQL

You might also like