Utkarsh Kumar Info Practical
Utkarsh Kumar Info Practical
1
Index
Index 2
Experiment 1 6
Given the school result data, analyze the performance of the
students on different parameters, e.g subject wise or class wise.
Experiment 2 7
Write a Program to create a DataFrame from a 2D array as shown
below:
Experiment 3 8
PQR is a list having three lists inside it. It contains summarized
data of three different trials conducted by company A. Create a bar
chart that plots these three sublists of PQR in a single chart. Keep
the width of each bar as 0.25. PQR = [[5, 25, 45, 20], [4, 23, 49,
17], [6, 22, 47, 19]]
Experiment 4 9
Write a program to iterate over a dataframe containing names and
marks which then calculates grades as per marks(as per guiding
below) and adds them to the grade column.
Marks >= 95 grade A+ ; Marks 50-60 grade C;
Marks 70-90 grade A ; Marks 40-50 grade D;
Marks 60-70 grade B ; Marks <40 grade E
Experiment 5 11
Given a series nfib that contains reversed Fibonacci numbers with
Fibonacci numbers as shown below:
Write a program to plot nfib with following specifications:
(a) The line color should be magenta.
(b) The marker edge color should be black with size 5.
(c) Grid should be displayed.
Experiment 6 12
2
Write a program to plot a scatter graph taking three random
distributions in A, B, C(all three with shape as (225, ) having
randomly generated integers) and Plotted against each other with
varying sizes.
Experiment 7 13
Sequences section and contri1 store the section names (‘A’, ‘B’,
‘C’, ‘D’, ‘E’) and contribution made by them respectively(6700,
5600, 5000, 5200, 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 a 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.
Experiment 8 14
Create an array, A, in the range 1 to 20 with values 1.25 apart.
Another array,B, contains the log values of the elements in the
array A. Write a program to create a scatter plot of first vs. second
array (array A vs. B) with red circle markers; specify the x-axis
(containing first array’s values) title as ‘Random Values’ and y-
axis title as ‘Logarithm Values’.
Experiment 9 15
Consider the saleDf shown below
Write a program to rename indexes of ‘ZoneW’ and ‘ZoneP’ as
‘Central’ and ‘Dakshin’ respectively and the column names
‘Target‘ and ‘Sales’ as ‘Targeted’ and ‘Achieved’ respectively.
Experiment 10 16
Write a python program to draw line charts from the given
financial data of XYZ Co. for 5 days in the form a DataFrame
namely fdf as shown below:
Experiment 11 17
Write a Pandas program to convert a dictionary to a Pandas series.
17
Experiment 12 18
Write a Pandas program to sort a given Series:
3
400, 300.12,100, 200
Experiment 13 19
Write a Pandas program to get the first 3 rows of a given
DataFrame.
Experiment 14 20
Write a Pandas program to sort the DataFrame first by 'name' in
descending order, then by 'score' in ascending order.
Experiment 15 21
Write a Pandas program to insert a new column in an existing
DataFrame.
Experiment 16 22
Write a Pandas program to combine two series into a DataFrame.
22
Experiment 17 23
Given a Series that stores the area of some states in km square.
Write code to find out the biggest and smallest three areas from the
given Series.
Experiment 18 25
Given an ndarray p as ([1, 2, 3, 4]). Write code to plot a bar chart
having bars for p and p**2 (with red colour) and another bar for p
and p*2 (with blue colour).
Experiment 19 26
Create a panda’s series from a dictionary of values and a ndarray.
26
Experiment 20 27
Consider the following tables CABHUB and CUSTOMER.
Experiment 21 31
Consider the following table GAME.
Write SQL Commands for the following statements:
Experiment 22 34
4
Create a student table with the student id, name, and marks as
attributes where the student id is the primary key.
Experiment 23 35
Insert the details of a new student in the above table.
Experiment 24 35
Delete the details of a student in the above table.
Experiment 25 36
Use the select command to get the details of the students with
marks more than 80.
Experiment 26 37
Find the min, max, sum, and average of the marks in a student
marks table.
Experiment 27 37
Write a SQL query to order the (student ID, marks) table in
descending order of the marks.
Experiment 28 38
Find the total number of customers from each country in the table
(customer ID, customer Name, country) using group by.
Experiment 29 39
Consider the following table named “DRINK”.
Write commands of SQL to display names and drink codes of those
drinks that have more than 120 calories.
Project 1 42
Project 2 47
—————————THE END—————————
5
Experiment 1
Input:
Input:
import pandas as pd
Values= [[100,150,175], [180,130,205], [210,116,217]]
Dataframe= pd.DataFrame(Values)
print(Dataframe)
Output:
0 1 2
0 100 150 175
1 180 130 205
2 210 116 217
7
Experiment 3
PQR is a list having three lists inside it. It contains summarized
data of three different trials conducted by company A. Create a
bar chart that plots these three sublists of PQR in a single chart.
Keep the width of each bar as 0.25. PQR = [[5, 25, 45, 20], [4,
23,
49, 17], [6, 22, 47, 19]]
Input:
import matplotlib.pyplot as pyp
import numpy
PQR = [[5, 25, 45, 20], [4, 23, 49, 17], [6, 22, 47, 19]]
pqr = numpy.arange(4)
pyp.bar(pqr, PQR[0], width=0.25, label="Trial 1")
pyp.bar(pqr+0.25, PQR[1], width=0.25, label="Trial 2")
pyp.bar(pqr+0.5, PQR[2], width=0.25, label="Trial 3")
pyp.xlabel("Trial Data")
pyp.ylabel("Y")
pyp.title("Company 'A' Data")
pyp.legend(loc="upper left")
pyp.savefig("C:\\Users\lab12\Desktop\Experiment 3.jpeg")
8
Experiment 4
Write a program to iterate over a dataframe containing names and
marks which then calculates grades as per marks(as per guiding
below) and adds them to the grade column.
Marks >= 95 grade A+ ; Marks 50-60 grade C;
Marks 70-90 grade A ; Marks 40-50 grade D;
Marks 60-70 grade B ; Marks <40 grade E
Input:
import pandas as
pd import numpy
as ny
names = pd.Series (["Ankit", "Pranjal", "Akhilesh", "Parag", "Utkarsh",
"Anmol", "Arush", "Ezaj"])
marks = pd. Series ([56, 78, 89, 37, 95, 76, 68, 76])
Stud = { 'Name': names, 'Marks': marks }
Result = pd.DataFrame (Stud, columns = ['Name', 'Marks'])
Result['Grade'] = ny.NaN
print ("Initial values in
dataframe") print (Result)
10
lstMrks.append('D')
else:
lstMrks.append('E')
Result['Grade'] = lstMrks
print("\n Dataframe after calculating grades")
print (Result)
Output:
Initial values in dataframe
Name Marks
Grade
0 Ankit 56 NaN
1 Pranjal 78 NaN
2 Akhilesh 89 NaN
3 Parag 37 NaN
4 Utkarsh 95 NaN
5 Anmol 76 NaN
6 Arush 68 NaN
7 Ezaj 76 NaN
11
Experiment 5
Given a series nfib that contains reversed Fibonacci numbers with
Fibonacci numbers as shown below:
[0, -1, -1, -2, -3, -5, -8, -13, -21, -34, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Write a program to plot nfib with following specifications:
(a) The line color should be magenta.
(b) The marker edge color should be black with size 5.
(c) Grid should be displayed.
Input:
import matplotlib.pyplot as pyp
nfib = [0, -1, -1, -2, -3, -5, -8, -13, -21, -34, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
pyp.plot(nfib, 'm*', markersize = 5, linestyle = 'solid', markeredgecolor = 'k')
pyp.grid(True)
pyp.savefig("C:\\Users\lab12\Desktop\Experiment 5.jpeg")
12
Experiment 6
Write a program to plot a scatter graph taking three random
distributions in A, B, C(all three with shape as (225, ) having
randomly generated integers) and Plotted against each other with
varying sizes.
Input:
import numpy as ny
import matplotlib.pyplot as pyp
A = ny.random.randint(1,225,
size=(225,)) B = ny.random.randint(1,225,
size=(225,)) C = ny.random.randint(1,225,
size=(225,)) pyp.scatter(C,A, color='k')
pyp.scatter(A,B, color='g')
pyp.scatter(A,C, color='b')
pyp.scatter(B,A, color='cyan')
pyp.scatter(B,C, color='silver')
pyp.scatter(C,B, color='olive')
pyp.savefig("C:\\Users\lab12\Desktop\Experiment 6.jpeg")
13
Experiment 7
Sequences section and contri1 store the section names (‘A’, ‘B’,
‘C’, ‘D’, ‘E’) and contribution made by them respectively(6700,
5600, 5000, 5200, 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 a 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.
Input:
import numpy as ny
import pandas as
pds
Sections = ["A", "B", "C", "D", "E"]
Contribution = [6700, 5600, 5000, 5200, ny.NaN]
Data = pds.Series( data = Contribution, index =Sections, dtype= ny.float32)
print("Donation by Others \n", Data)
Donation = pds.Series(Data*2)
print("Donation by School \n", Donation)
Output:
Donation by
Others A
6700.0
B 5600.0
C 5000.0
D 5200.0
E NaN
dtype: float32
Donation by
School A
13400.0
B 11200.0
C 10000.0
D 10400.0
14
E
NaN
d
t
y
p
e
:
f
l
o
a
t
3
2
15
Experiment 8
Create an array, A, in the range 1 to 20 with values 1.25 apart.
Another array,B, contains the log values of the elements in the
array A. Write a program to create a scatter plot of first vs.
second array (array A vs. B) with red circle markers; specify the
x-axis (containing first array’s values) title as ‘Random Values’
and y-axis title as ‘Logarithm Values’.
Input:
import matplotlib.pyplot as pyp
import numpy as ny
A=
ny.arange(1,20,1.25) B
= ny.log(A) pyp.plot(A,
B, 'ro')
pyp.xlabel('Random Values')
pyp.ylabel("Logarithmic Values")
pyp.savefig("C:\\Users\lab12\Desktop\Experiment 8")
16
Experiment 9
Consider the saleDf shown below
Target Sales
ZoneX 56000 58000
ZoneY 70000 68000
ZoneW 75000 78000
ZoneP 60000 61000
Input:
import pandas as pds
A = [56000, 70000, 75000, 60000]
B = [58000, 68000, 78000, 61000]
Zones = ["ZoneX", "ZoneY", "ZoneW", "ZoneP"]
Col = {"Target":A, "Sales":B}
SaleDF = pds.DataFrame(Col, index= Zones)
print(SaleDF)
SaleDF.index=["ZoneX", "ZoneY", "Central", "Daksin"]
SaleDF.columns=["Targeted", "Achieved"]
print(SaleDF)
Output:
Target Sales
ZoneX 56000 58000
ZoneY 70000 68000
ZoneW 75000 78000
ZoneP 60000 61000
17
Targeted Achieved
ZoneX 56000 58000
ZoneY 70000 68000
Central 75000 78000
Daksin 60000 61000
Experiment 10
Write a python program to draw line charts from the given
financial data of XYZ Co. for 5 days in the form a DataFrame
namely fdf as shown below:
Day1 Day2 Day3 Day4 Day5
0 74.25 56.03 59.30 69.00 89.65
1 76.06 68.71 72.07 78.47 79.65
2 69.50 62.89 77.65 65.53 80.75
3 72.55 56.42 66.46 76.85 85.08
Input:
import pandas as pds
import matplotlib.pyplot as pyp
D1 = [74.25, 76.06, 69.50, 72.55]
D2 = [56.03, 68.71, 62.89, 56.42]
D3 = [59.30, 72.07, 77.65, 66.46]
D4 = [69.00, 78.47, 65.53, 76.85]
D5 = [89.65, 79.65, 80.75, 85.08]
Dict = {"Day1":D1, "Day2":D2, "Day3":D3, "Day4":D4, "Day5":D5}
fdf = pds.DataFrame(Dict)
fdf.plot()
pyp.legend(loc=1)
pyp.savefig("C:\\Users\lab12\Desktop\Experiment 10")
18
Experiment 11
Write a Pandas program to convert a dictionary to a Pandas series.
Sample dictionary: d1 = {“a”:100, “b”: 200, “C”: 300}
Input:
import pandas as pds
d1 = {'a' :100, 'b': 200, 'C': 300}
Series1=
pds.Series(d1)
print(Series1)
Output:
a 100
b 200
C 300
dtype: int64
19
Experiment 12
Write a Pandas program to sort a given Series:
400, 300.12,100, 200
Input:
import pandas as pds
Data = [400, 300.12,100, 200]
Series2=
pds.Series(Data)
print(Series2)
print("\n Values Sorted:")
print(Series2.sort_values)
print("\n Index Sorted:")
print(Series2.sort_index)
Output:
0 400.00
1 300.12
2 100.00
3 200.00
dtype: float64
Values Sorted:
0 400.00
1 300.12
2 100.00
3 200.00
dtype: float64>
Index Sorted:
0 400.00
1 300.12
2 100.00
3 200.00
dtype: float64>
20
Experiment 13
Write a Pandas program to get the first 3 rows of a given
DataFrame.
Input:
import pandas as pds
D1 = [74.25, 76.06, 69.50, 72.55]
D2 = [56.03, 68.71, 62.89, 56.42]
D3 = [59.30, 72.07, 77.65, 66.46]
D4 = [69.00, 78.47, 65.53, 76.85]
D5 = [89.65, 79.65, 80.75, 85.08]
Dict = {"Day1":D1, "Day2":D2, "Day3":D3, "Day4":D4, "Day5":D5}
Dataframe1 = pds.DataFrame(Dict)
print("Actual Dataframe")
print(Dataframe1)
print("Retrived Three Rows")
print(Dataframe1.loc[0:2,:])
Output:
Actual Dataframe
Day1 Day2 Day3 Day4 Day5
0 74.25 56.03 59.30 69.00 89.65
1 76.06 68.71 72.07 78.47 79.65
2 69.50 62.89 77.65 65.53 80.75
3 72.55 56.42 66.46 76.85 85.08
21
Experiment 14
Write a Pandas program to sort the DataFrame first by 'name' in
descending order, then by 'score' in ascending order.
Input:
import pandas as pds
Roll_no = [311, 312, 313, 314, 315, 316, 317, 318]
Score = [74.25, 76.06, 69.50, 72.55, 59.30, 72.07, 77.65, 66.46]
Names = ["Ankit", "Pranjal", "Anmol", "Arush", "Ashutosh", "Aman",
"Abhiram", "Parag"]
Dict = {"Roll no": Roll_no, "Names":Names, "Score": Score}
Dataframe2 = pds.DataFrame(Dict)
print(Dataframe2)
print("\n Sorting by Names") #\n to print the output after leaving a line
print(Dataframe2.sort_values(by='Names',ascending=False))
print("\n Sorting by Score")
print(Dataframe2.sort_values(by='Score',ascending=True))
Output:
Roll no Names
Score 0 311
Ankit 74.25
1 312 Pranjal 76.06
2 313 Anmol 69.50
3 314 Arush 72.55
4 315 Ashutosh 59.30
5 316 Aman 72.07
6 317 Abhiram 77.65
7 318 Parag 66.46
22
Sorting by Names
Roll no Names Score
1 312 Pranjal 76.06
4 315 Ashutosh 59.30
7 318 Parag 66.46
3 314 Arush 72.55
0 311 Ankit 74.25
2 313 Anmol 69.50
5 316 Aman 72.07
6 317 Abhiram 77.65
Sorting by Score
Roll no Names Score
4 315 Ashutosh 59.30
7 318 Parag 66.46
2 313 Anmol 69.50
5 316 Aman 72.07
3 314 Arush 72.55
0 311 Ankit 4.25
1 312 Pranjal 76.06
6 317 Abhiram 77.65
Experiment 15
Write a Pandas program to insert a new column in an existing
DataFrame.
Input:
import pandas as pds
D1 = [74.25, 76.06, 69.50, 72.55]
D2 = [56.03, 68.71, 62.89, 56.42]
D3 = [59.30, 72.07, 77.65, 66.46]
D4 = [69.00, 78.47, 65.53, 76.85]
D5 = [89.65, 79.65, 80.75, 85.08]
Names = ["Hardik", "Avtrit", "Utkarsh", "Parag"]
23
Dict = {"Names": Names, "English":D1, "Hindi":D2, "Maths":D3,
"Science":D4}
Dataframe3 = pds.DataFrame(Dict)
print("Actual Dataframe")
print(Dataframe3)
Dataframe3["SST"]=D5
print("\n New Dataframe") #\n to print the output after leaving a line
print(Dataframe3)
Output:
Actual Dataframe
Names English Hindi Maths Science
0 Hardik 74.25 56.03 59.30 69.00
1 Avtrit 76.06 68.71 72.07 78.47
2 Utkarsh 69.50 62.89 77.65 65.53
3 Parag 72.55 56.42 66.46 76.85
New Dataframe
Names English Hindi Maths Science SST
0 Atharv 74.25 56.03 59.30 69.00 89.65
1 Avtrit 76.06 68.71 72.07 78.47 79.65
2 69.50 62.89 77.65 65.53 80.75
Utkarsh
3 Parag 72.55 56.42 66.46 76.85 85.08
Experiment 16
Write a Pandas program to combine two series into a DataFrame.
Input:
import pandas as pds
D1 = pds.Series([74.25, 76.06, 69.50, 72.55])
D2 = pds.Series([56.03, 68.71, 62.89, 56.42])
D3 = pds.Series([59.30, 72.07, 77.65, 66.46])
24
D4 = pds.Series([69.00, 78.47, 65.53, 76.85])
25
print("Individual Series")
print(D1, D2, D3, D4)
Data= [D1, D2, D3, D4]
Dataframe4= pds.DataFrame(Data)
print("Serieses into Dataframe")
print(Dataframe4)
Output:
Individual Series
0 74.25
1 76.06
2 69.50
3 72.55
dtype: float64
0 56.03
1 68.71
2 62.89
3 56.42
dtype: float64
0 59.30
1 72.07
2 77.65
3 66.46
dtype: float64
0 69.00
1 78.47
2 65.53
3 76.85
dtype: float64
Serieses into
Dataframe 0 12
3
0 74.25 76.06 69.50 72.55
1 56.03 68.71 62.89 56.42
2 59.30 72.07 77.65 66.46
3 69.00 78.47 65.53 76.85
26
Experiment 17
Given a Series that stores the area of some states in km square.
Write code to find out the biggest and smallest three areas from
the given Series.
Input:
import pandas as pds
Ser5=pds.Series([34567, 890, 450, 67892, 34677, 78902, 256711, 678291,
637632, 25723, 2367, 11789, 345, 256517])
print("The three Smallest states")
print(Ser5.sort_values(ascending=True).head(3))
print("The three Smallest states")
print(Ser5.sort_values(ascending=False).tail(3))
Output:
The three Smallest
states 12 345
2 450
1 890
dtype: int64
The three Largest
states 1 890
2 450
12 345
dtype: int64
27
Experiment 18
Given an ndarray p as ([1, 2, 3, 4]). Write code to plot a bar chart
having bars for p and p**2 (with red colour) and another bar for p
and p*2 (with blue colour).
Input:
import matplotlib.pyplot as pyp
import numpy as ny
P = ny.array([1, 2, 3, 4])
Q = P**2
pyp.bar(P, P**2, width=0.4, color='r', label="P**2")
pyp.bar(P+0.4, P*2, width=0.4, color='b', label="P*2" )
pyp.legend(loc=2)
pyp.title("Graph of Numbers") pyp.savefig("C:\\Users\lab12\Desktop\
Experiment 18")
28
Experiment 19
Create a panda’s series from a dictionary of values and a ndarray.
(I) Input:
import pandas as pds
D1 = [74.25, 76.06, 69.50, 72.55]
D2 = [56.03, 68.71, 62.89, 56.42]
D3 = [59.30, 72.07, 77.65, 66.46]
D4 = [69.00, 78.47, 65.53, 76.85]
Names = ["Hardik", "Avtrit", "Utkarsh", "Harsh"]
Dict = {"Names": Names, "English":D1, "Hindi":D2, "Maths":D3,
"Science":D4}
Series5 = pds.Series(Dict)
print(Series5)
Output:
Names [Hardik, Avtrit, Utkarsh, Harsh]
English [74.25, 76.06, 69.50, 72.55]
Hindi [56.03, 68.71, 62.89, 56.42]
Maths [59.30, 72.07, 77.65, 66.46]
Science [69.00, 78.47, 65.53, 76.85]
dtype: object
(II) Input:
import pandas as
pds import numpy
as ny S1 =
ny.arange(10) S2 =
S1**2
Series6 = pds.Series(S2, index=S1)
print(Series6)
29
Output:
0 0
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81
dtype: int32
Experiment 20
Consider the following tables CABHUB and CUSTOMER.
30
SQL:
mysql> create Database Info_Practicals;
Query OK, 1 row affected (0.01 sec)
31
| 3 | Feroz Shah | 105 |
| 4 | Ketan Dhal | 104 |
+ + +
+ 4 rows in set (0.01
sec)
32
(a)
mysql> select * from Cabhub where Colour="White";
+ + + + + + +
| Vcode | VehicleName | Make | Colour | Capacity | Charges |
+ + + + + + +
| 100 | Innova | Toyota | White | 7| 15 |
| 105 | A Star | Suzuki | White | 3| 14 |
+ + + + + +
+ 2 rows in set (0.01 sec)
(b)
mysql> select VehicleName, Capacity from Cabhub order by Capacity;
+ + +
| VehicleName | Capacity |
+ + +
| A Star | 3|
| Indigo | 3|
| SX4 | 4|
| C Class | 4|
| Innova | 7|
+ +
+ 5 rows in
set (0.02 sec)
(c)
mysql> select Max(Charges) from cabhub;
+ +
| Max(Charges) |
+ +
| 35|
+ +
1 row in set (0.02 sec)
(d)
mysql> Select Cname, Vehiclename from Customer, Cabhub where
customer.Vcode=cabhub.vcode;
+ + +
| Cname | Vehiclename |
+ + +
| Ketan Dhal | C Class |
| Feroz Shah | A Star |
| Raj Lal | Indigo |
+ + +
33
3 rows in set (0.00 sec)
Experiment 21
Consider the following table GAME.
SQL:
mysql> insert into Game values(101, "Carom Board", "Indoor", 2,
5000, "2023-01-23");
Query OK, 1 row affected (0.02 sec)
34
mysql> insert into Game values(105, "Chess", "Indoor", 2,
9000, "2004-01-01");
Query OK, 1 row affected (0.01 sec)
(a)
mysql> select * from game where Prize_Money>7000;
+ + + + + + +
| Gcode | Game_Name | Type | Number | Prize_Money | Schedule_Date |
+ + + + + + +
| 102 | Badminton | Outdoor | 2 | 12000 | 2023-12-12 |
| 103 | Table Tennis | Indoor | 4 | 8000 | 2004-02-14 |
| 105 | Chess | Indoor | 2| 9000 | 2004-01-01 |
| 108 | Lawn Tennis | Outdoor | 4 | 25000 | 2004-03-19 |
+ + + + + +
+ 4 rows in set (0.01 sec)
(b)
mysql> select * from game order by Schedule_Date;
+ + + + + + +
| Gcode | Game_Name | Type | Number | Prize_Money | Schedule_Date |
+ + + + + + +
| 105 | Chess | Indoor | 2| 9000 | 2004-01-01 |
| 103 | Table Tennis | Indoor | 4 | 8000 | 2004-02-14 |
| 108 | Lawn Tennis | Outdoor | 4 | 25000 | 2004-03-19 |
| 101 | Carom Board | Indoor | 2| 5000 | 2023-01-23 |
| 102 | Badminton | Outdoor | 2 | 12000 | 2023-12-12 |
+ + + + + + +
35
5 rows in set (0.00 sec)
(c)
mysql> select type, Sum(Prize_Money) from Game group by Type;
+ + +
| type | Sum(Prize_Money) |
+ + +
| Indoor | 22000 |
| Outdoor | 37000 |
+ +
+ 2 rows in set
(0.01 sec)
36
Experiment 22
Create a student table with the student id, name, and marks as
attributes where the student id is the primary key.
SQL:
mysql> create table Students(Student_id int Primary Key, Name Char (40),
Marks int);
Query OK, 0 rows affected (0.02 sec)
37
mysql> desc students;
+ + + + + + +
| Field | Type | Null | Key | Default | Extra |
+ + + + + + +
| Student_id| int(11) | NO | PRI | NULL | |
| Name | char(40) | YES | | NULL | |
| Marks | int(11) | YES | | NULL | |
+ + + + + +
+ 3 rows in set (0.03 sec)
Experiment 23
Insert the details of a new student in the above table.
SQL:
mysql> insert into Students Values(3215, "Akhilesh", 54);
Query OK, 1 row affected (0.01 sec)
Experiment 24
Delete the details of a student in the above table.
38
SQL:
mysql> delete from Students where Student_id=3208;
Query OK, 1 row affected (0.01 sec)
Experiment 25
Use the select command to get the details of the students with
marks more than 80.
SQL:
mysql> select * from Students where marks>80;
+ + + +
| Student_id | Name | Marks |
+ + + +
| 3214 | Anmol | 97 |
| 3204 | Avtrit | 86 |
| 3217 | Harsh | 81 |
+ + +
+ 3 rows in set
(0.00 sec)
39
Experiment 26
Find the min, max, sum, and average of the marks in a student
marks table.
SQL:
mysql> select min(marks), max(marks), sum(marks), avg(marks) from
Students;
+ + + + +
| min(marks) | max(marks) | sum(marks) | avg(marks) |
+ + + + +
| 54| 97 | 466 | 77.6667 |
+ + + +
+ 1 row in set (0.01 sec)
Experiment 27
Write a SQL query to order the (student ID, marks) table in
descending order of the marks.
SQL:
mysql> select Student_id, Marks from Students order by Marks desc;
+ + +
| Student_id | Marks |
+ + +
| 3214 | 97 |
| 3204 | 86 |
| 3217 | 81 |
| 3224 | 79 |
| 3200 | 69 |
| 3215 | 54 |
+ +
+ 6 rows in
set (0.00 sec)
40
Experiment 28
Find the total number of customers from each country in the table
(customer ID, customer Name, country) using group by.
SQL:
mysql> create table Customers (Customer_id int, Customer_name Char (35),
Country Char (40));
Query OK, 0 rows affected (0.01 sec)
41
mysql> select * from Customers;
+ + + +
| Customer_id | Customer_name | Country |
+ + + +
| 125785 | Francis | France |
| 167585 | Zodin | England |
| 164365 | Swami | India |
| 123365 | Uttam | India |
| 124357 | Shishu | India |
| 185457 | Prashant | Germany|
| 178457 | Zuarin | Germany|
| 197557 | Sukole | England |
| 199857 | Shuko | India |
+ + +
+ 9 rows in set (0.00 sec)
mysql> select country, count(*) from Customers group by Country;
+ + +
| country | count(*) |
+ + +
| England | 2|
| France | 1|
| Germany| 2|
| India | 4|
+ + +
4 rows in set (0.00
sec)
Experiment 29
Consider the following table named “DRINK”.
DNAME
DRINKCODE PRICE CALORIES
42
102 Apple Drink 18 120
SQL:
mysql> create table Drink(DrinkCode int, Dname Char (20), Price int,
Calories int);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into Drink values(101, "Lime and Lemon", 20, 120);
Query OK, 1 row affected (0.01 sec)
mysql> insert into Drink values(106, "Mango Juice Bahar", 12, 150);
43
Query OK, 1 row affected (0.00 sec)
44
Project 1
# Exporting data between pandas and Csv file.
Output:
Adm no Name English Maths Info Percentage
0 3215 Akhilesh 78 23 76 59
1 3210 Tuan 96 76 86 86
2 3224 Parag 89 34 48 57
3 3199 Utkarsh 65 46 45 52
4 3207 Ezaj 33 87 87 69
5 3220 Abhiram 56 56 56 56
6 3200 Hardik 77 34 33 48
7 3221 Arush 23 98 23 48
8 3208 Ankit 98 76 87 87
9 3204 Avtrit 45 55 65 55
10 3222 Aman 74 87 67 76
45
# Importing data between pandas and csv file.
import pandas as pds
Marksheet = pds.read_csv("C:\\Users\lab12\Desktop\Marksheet.csv")
print(Marksheet)
Output:
Adm no Name English Maths Info Percentage
0 3215 Akhilesh 78 23 76 59
1 3210 Tuan 96 76 86 86
2 3224 Parag 89 34 48 57
3 3199 Utkarsh 65 46 45 52
4 3207 Ezaj 33 87 87 69
5 3220 Abhiram 56 56 56 56
6 3200 Hardik 77 34 33 48
7 3221 Arush 23 98 23 48
8 3208 Ankit 98 76 87 87
9 3204 Avtrit 45 55 65 55
10 3222 Aman 74 87 67 76
Output:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 11 entries, 0 to 10
Data columns (total 6 columns):
Adm no 11 non-null int64
Name 11 non-null object
English 11 non-null int64
Maths 11 non-null int64
Info 11 non-null
int64 Percentage 11 non-null
int64 dtypes: int64(5), object(1)
memory usage: 616.0+ bytes
None
46
# To display the shape (number of rows and columns) of the
csv file.
import pandas as pds
Marksheet = pds.read_csv("C:\\Users\lab12\Desktop\Marksheet.csv")
print(Marksheet.shape)
Output:
(11, 6)
Output:
Adm no Name Percentage
0 3215 Akhilesh 59
1 3210 Tuan 86
2 3224 Parag 57
3 3199 Utkarsh 52
4 3207 Ezaj 69
5 3220 Abhiram 56
6 3200 Hardik 48
7 3221 Arush 48
8 3208 Ankit 87
9 3204 Avtrit 55
10 3222 Aman 76
47
# To display the first 5 and last 5 records from
‘Marksheet.csv’ file.
import pandas as pds
Marksheet = pds.read_csv("C:\\Users\lab12\Desktop\Marksheet.csv")
print(Marksheet.head())
print(Marksheet.tail()) # There is no need to mention a value within parenthesis
as default value for both head and tail functions is 5.
Output:
Adm no Name English Maths Info Percentage
3215 Akhilesh 78 23 76 59
1 3210 Tuan 96 76 86 86
2 3224 Parag 89 34 48 57
3 3199 Utkarsh 65 46 45 52
4 3207 Ezaj 33 87 87 69
48
Output:
College no Good name Eng Mathematics Info %
0 3215 Akhilesh 78 23 76 59
1 3210 Tuan 96 76 86 86
2 3224 Parag 89 34 48 57
3 3199 Utkarsh 65 46 45 52
4 3207 Ezaj 33 87 87 69
5 3220 Abhiram 56 56 56 56
6 3200 Hardik 77 34 33 48
7 3221 Arush 23 98 23 48
8 3208 Ankit 98 76 87 87
9 3204 Avtrit 45 55 65 55
10 3222 Aman 74 87 67 76
as ny
Marksheet = pds.read_csv("C:\\Users\lab12\Desktop\Marksheet.csv")
Marksheet.loc[Marksheet['Percentage']<50, 'Percentage']=ny.NaN
print(Marksheet)
Output:
Adm no Name English Maths Info Percentage
0 3215 Akhilesh 78 23 76 59.0
1 3210 Tuan 96 76 86 86.0
2 3224 Parag 89 34 48 57.0
3 3199 Utkarsh 65 46 45 52.0
4 3207 Ezaj 33 87 87 69.0
5 3220 Abhiram 56 56 56 56.0
6 3200 Hardik 77 34 33 NaN
7 3221 Arush 23 98 23 NaN
8 3208 Ankit 98 76 87 87.0
9 3207 Avtrit 45 55 65 55.0
10 3222 Aman 74 87 67 76.0
49
Project 2
# Data Visualization of Covid analysis with csv file.
import pandas as pds
import matplotlib.pyplot as pyp
Covid_Data = pds.read_csv("C:\\Users\lab12\Desktop\Covid Data.csv")
print(Covid_Data)
Day1 = Covid_Data.iloc[:, 1:2]
pyp.plot(Day1, color='k', label = "Day 1")
Day2 = Covid_Data.iloc[:, 2:3]
pyp.plot(Day2, color='g', label = "Day 2")
Day3 = Covid_Data.iloc[:, 3:4]
pyp.plot(Day3, color='r', label = "Day 3")
pyp.legend()
pyp.savefig("C:\\Users\lab12\Desktop\Project1")
Output:
50
13 Jammu and Kashmir 30 278 60
14 Jharkhand 0 27 0
15 Karnataka 75 277 150
16 Kerala 211 387 422
17 Ladakh 10 17 20
18 Madhya Pradesh 64 97 128
19 Maharashtra 259 287 518
20 Manipur 1 2 2
21 Meghalaya 6 7 12
22 Mizoram 8 1 16
23 Nagaland 5 3 10
24 Odisha 18 60 36
25 Puducherry 1 7 2
26 Punjab 14 186 28
27 Rajasthan 147 105 294
28 Tamil Nadu 81 120 162
29 Telangana 120 647 240
30 Tripura 0 2 0
31 Uttarakhand 9 37 18
32 Uttar Pradesh 51 75 102
33 West Bengal 37 213 74
51
—————————THE END—————————
52