0 ratings0% found this document useful (0 votes) 35 views27 pagesPractical File IP
class 12 IP practical file
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Suggested Practical List .
1 Data Handling
1. Create a panda’s series from a dictionary of values and a ndarray
2. Given a Series, print all the elements that are above the 75th percentile,
3. Create a Data Frame quarterly sales where each row contains the item]
category, item name, and expenditure. Group the rows by the category and print
the total expenditure per category.
4, Create a data frame for examination result and display row labels, column]
labels data types of each column and the dimensions
5. Filter out rows based on different criteria such as duplicate rows
6. Importing and exporting data between pandas and CSV file
2 Visualization
1. Given the school result data, analyses the performance of the students on]
different parameters, e.g subject wise or class wise
2. For the Data frames created above, analyze, and plot appropriate charts with}
title and legend.
3. Take data of your interest from an open source (c.g. data.gov.in), aggregate}
and summarize it. Then plot it using different plotting functions of the Matplotlib
library.
3 Data Management
1. Create a student table with the student id, name, and marks as attributes wherd
the student id is the primary key.
2. Insert the details of a new student in the above table.
3. Delete the details of a student in the above table.
4, Use the select command to get the details of the students with marks more than]
80.
5. Find the min, max, sum, and average of the marks in a student marks table.
6. Find the total number of customers from each country in the table (customer
ID, customer Name, country) using group by. 7. Write a SQL query to order the|
(student ID, marks) table in descending order of the marks.STUDENT PROFILE
xXuc
Informatics Practices
Name of
Student
Fathers Name
Contract
Number
ADARSH
PANDEY
SATENDRA KUMAR
PANDEY
9426379606
AKANSHA
GHANSHYAM KOGE
8150076619
BHAVIKA
HARESHKUMAR
MAKHUA
HARESHKUMAR
KEWALRAM
MAKHUA
S128588548.
DIP ROY
DEBASHISH ROY
8871690895
FENI
IAGDISHBHAT
SOLGAMA.
JAGDISH BHAT
SOLGAMA,
19909016032
GAURAV G NAIR
GURUVAYURAPPAN
7600852214
HARISHIKESH
MODI
ASHOK MODI
9328880999
ISHITA SINGLA
‘AMIT SINGLA
7986366261
TAYDEEP SINGH
P.ASR. BHAI
(9737587840
KADRI RUSHAN
KADRI NAIM
‘9714399011
RAHUL
MANOHARAN
MANOHARAN.P
9048627524
SHAMMI
KUMARIJ OJHA.
JAY PRAKASH OJHA
8000708000.
SUNNY SINGH
CHAUHAN.
CHAUHAN SARVAN
SINGH.
8936078212STUDENT PROFILE
XID
Informatics Practices
Name of Student
Fathers Name
Contract
Number
PATEL YASH
KAMLESHBHAL
KAMLESH BHAL
9879184274
ANNWESA
MUKHOPADHYAY,
MEGHNAD
MUKHOPADHYAY
9920518749
SOURAV BHOSLE
SUBHASH
9998076143,
NISHANT
CHOUDHARY
DILIP KUMAR
CHOUDHARY,
9501098305
SUBHAM DUTTA
SANTOSH KUMAR
DUTTA,
9893205041
MD NUAMUL,
HEQUE,
MD SHERFUL,
HEQUE
9520205712
ANUSKA YADAV,
SAHIL
CHATURVEDI
VIRENDRA
CHATURVEDI
UMASHANKAR
9519680898
9518878233,#1 Create a pandas series from a dictionary of values and an ndarray.
inport pandas as pd
import nunpy as np
s=pd.Series(np.array((1,3,4,7,8,8,9]))
print(s)
e
1
2
3
4
5
6
a
type: int32
# import the pandas Lib as pd
‘inport pandas as pd
# create 0 dictionary
dictionary = {'A' : 18, 'B' : 28, 'C’ : 38)
# create a series
series = pd.Series(dictionary)
print series)
A
8 we
¢
types inte#2. Given Series, print all the elements that are above the 75th percentile.
ingort pandas as pd
ingort nunpy as np
sepd.Series(np.array({1,3,4,7,8,8,9]))
print(s)
reses.quantile(q-0.75)
print()
print('75th Percentile of the series is
print(res)
print()
print(’The elenents that are above the 75th pencentile::")
print(s[sores))
8
1
2
3
4
5
6
at
type: int32
75th Percentile of the series 4:
8.0
The elenents that are above the 75th percentile::
6 9
dtype: int32#3 Create a Data Frame quarterly sales where each row contains the item
category, itemname, and expenditure. Group the rows by the categor
import pandas as pd
"Washing Hachine"],
phony’ ,'L6'],
ture" :[7ee@8e2, See, 12600, 14800)]}
Guartsales=pd.DataFrane(dic)
print(quartsales)
qs-quartsales. groupby( itencat')
print(‘Result after Filtering Datafrane')
print(qs["itencat', ‘expenditure’ .sun())
itencat itemane expenditure
@ ar Ford 7990008
1 Ac Hitachi 50088
2 Aircoller symphony 12008
3 Washing Yachine —LG-_—=—4000
Result after Filtering Datafrane
expenditure
itencat
Ac 080
Aircoller 12600
Washing Machine 14800
car Teeeeee#4. Create a data frame based on ecommerce data and generate descriptive
statistics (mean, median, mode, quartile, and varianc
inport pandas as pd
sales = {'Tnvoicelo': [10011002 1003, 100, 1085, 1086, 1207],
"Productllane': ['LED','Ac',Deodrant, "Jeans, Boks’, 'Shoes’ Jacket"),
‘Quantity’s (2,1,21,21,1),,
65000, 55000, 380, 2500, 958, 3800, 2208)
Datafrane(sils)
print (df ‘Price’ describe). round(2)]
‘count 7.08
mean 18450.00
std 28543.61
500.28
1575.08
5a 500.00
20208.20
max 65208.00
Nate: Price, dtype: float#5. Create a data frame for examination result and
labels data types of each column and the dimensions
import pandas as pd
dice{’Class':['1',"IU', 10", "1V','V','V0',"VI0', ‘VII’, "IX," "X01, XI"),
“pass-Percentage’:[100, 108, 108,100, 108, 100,108, 100,100, $8.6, 109,96] }
resultepdDatafrane(dic)
print(result)
print(result.dtypes)
print( shape of the datafrane is:::
print(result. shape)
Class Pass-Percentage
I 100.8
Ir 100.8
ut 100.8
WV 100.8
v 100.8
Wt 100.8
va 100.8
100.8
m 100.8
x 98.6
x 100.8
i XI 99.8
lass object
Pass-Percentage float
types object
shape of the datafrane is:::
(12, 2)Iter out rows based on different uch as duplicate rot
ingort pandas as pd
dice('Nane':['Rohit', ‘Mohit’ "Deepak, Rohit’, ‘Deepak’, "Soht’, Geeta],
"WarksinIP' :[85, 45,92,85,92,96,84]}
narksepd.DataFrane(ic)
# Find duplicate rows
uplicateRow = narks{narks. duplicated (keep-False)
print (dup icateRow)
Name HarksintP
@ Rohit &
2 Deepak 2
3° Rohit &
4 Deepak 2\d the sum of each column, or find the column with the lowest mean.
‘import pandas as pd
Profitef "TCS": { ‘Qtrt':2508, ‘Qtr2": 2008, "Qtr3": 3000, ‘Qtra’: 2000},
WIPRO": {Qtr 2800, "Qtr2 2480, ‘tra: 3608, Qtr" :24@0},
LAT’: { “tra :2100, 'gtr2’:5709,Qte3":35000, ‘Qtra’:2100})
fepd. Datafrane Profit)
print(@F)
print()
print(‘Colunn wise sun in datfrane is :
print (dF.sum(axiss0))
# Print mean value of each coluan
print()
print(‘column wise sean value are::
print(@F.nean(axis-2))
# Returns Column with minimum neon volue
print()
print(‘colunn with miniun nean value is
(f mean(axis=2) idxmin()
Tes MIRO. LAT
Qtri 25e0 2880 2160
Qtr2 20¢@ ©2420 5780
Qtr3. 39¢0 3680 35080
Qtr4 2000 2400 2160
Column wise sum in datframe is :::
1s 9500
WIPRO 11200
ler 4agee
type: ints
Column wise mean value are:::2::::1
ms 2375.8
WIPRO 2800.8
ur 1125.0
type: floates
Column with minimue mean value is::::
"1s"Locate the 3 largest values in a data frame.
‘inport pandas as pd
dice{'Nane' :['Rohit',‘Yohit", ‘Deepak’, ‘Anil’, ‘Pankaj’, ‘Sohit', “Geeta'],
HarksinIP’:[85,45,92,85,08,96,04]}
rarksspdDataFrane( ic)
# Find 3 Lorgest Value for Norksind? Coluan
print(nanks.nlargest(3,['NarksinlP']))
Name MarksinIP
4 Pankaj %
5 Sohit %
2 Deepak 2#9. Subtract the mean of a row from each element of the row in a Data Framé
nport pandas as o¢
Profitet ‘TCS's { “Gtrd':2568 "Qtrd':200e, Qtr}: 200, "Qt 200},
vdPRO': {'Gtrt":2880, "Qtra':240, "Qtr: 360, "Qt 208},
UT's { "Qtr :206@, "Qtr" :57ae, "Qt :35ee, "gtd 2188)
staFren(Profit)
a ofeach rn is
print df, mean( ad
print(
print "atfrene aftr Subtracting mean value ofeach row fron
print(.sub(d.mean(adse1),axis))
TCS MIRO LAT
Qtrt 2508 2802 2100
tra 2008 2H0e 5708
tra 3200 3602 35008
tra 20008 2402 2108
ean oF each row 4s
tri 2466. 666667
tr? 3366.656667
ted 1386666667
tre 2166.666667
types floats
Datafrane after Subtracting mean value of each row fron each elenent of that Row is ::
1s WIPRO ur
Qtr 33,393333333.333333 -366.666667
rd. -1366.666667 -966, 656667 7333,233323
tr -10866.666667 -10266. 656667 21133.333333,
tra -166.666667 233.333333 -66.666667#10. Replace all negative values in a data frame with a
‘injort pandas as pd
Ac Datal':[-5,-25,8,9,-6],
‘Datad':[2,4,10,15, -5,-8]}
apd DtaFrane( tic)
print(df)
print()
print(“datafrane after replacing negative values with @:::")
Fd)
print(df)
Datal
datafrane after replacing negative values vith 0
Datel Data
6 2
4
10
6a data frame with a 999.
‘nport nunpy a m9
cmpdatae{ ‘enpid's[101, 102,103, 104,105,106],
enn ‘Sachin’ Viol 'Lakibr’pp.nan, ‘Dende’, Unaselvi),
‘Doj':[*12-@1-2812' '15-@1-2012 09-2067" ,'17-@1- 2012' np. nan, '16-@1-2012"]}
fp. DataFrane(emtata)
print(df)
ted Fla {'erane':89, 00
print()
print)
emiderame
301 Sachin 12-81-2012
102 Vinod 15-81-2012
183 Lakhbir 65-29-2087
14 Wal 17-€1- 2012
105 Devinder Nak
106 UnaSelvi 16-81-2012
emid ene Oj
el Sachin 12-€1-2812
1 Vinod 1541-2012
103 Lakhbir 65-29-2087
te 999 17-€1- 2012
105 Devinder 999
16 UnaSelvd 641-202e
a
2
# importing pandas nodule
inport pandas as pd
# making data frane
4 dF = pd.read_csv("E:\emp.csv")
print (dF)
enpid ‘enane 40}
401 Sachin Bhardwaj 12-01-2012
102 Vinod Verma 15-01-2012
103 Anand Ganesh 05-09-2007
1 import pandas as pd
1 [{'Nane': "Sachin Bharduaj"},
{'Nane': "Vinod, erna’},
{ ‘Name's ‘Rajesh’, '
flepd.Datafrane(1)
# saving the datafrane
fl to_csv(E:\Datafranel csv")
Name SirName
0 Sachin Bhardwaj
1Vinod Verma
2 Rajesh Mishra#13. Importing and exporting data between pandas and MySQL database.
Importing Data from MySQL to Data Frame.
1 (1): por pandas as pt
10 [2s port ysl comector
In [5]: cmos. cometorcomect hosts" locas" usrs ont" passus"root, attasesschi")
prst( cn)
‘ays. comectorcamactionyse.cmection object at terror irr>
18 (6): ems. read se, qu show tales fron sachin” ca)
"
Gust): esi
enpoyeeExporting data from Data Frame to MYSQL.
ingot sq. comector
igort pnd asp
conays].comectorcomec(h st pasa rot database sechi")
con,comit)
farous) in
us" ead "+ ee
ays. ct at oncom
mid eum
ve sachin 2-0-2
12-81-15
ir mT -8.45
Anil 2012-
Oevinder 2007-29-05
sel ML--16
Fr sucessfully
as ar es
ee ee
1 Peery
ree eter]
1)#14, Given the school result data, analyse the performance of the students on
different parameters, e.g subject wise or class wi:
Subjects ‘Physics’, 'Chnistr', "Hind, "Bflogy*,"Conutersc']
Poncentago[85,78,65,9,10
plt.bar Subject, Percentage align’ center’ color» green’)
pltxabel( ‘UBIECTS ')
plt.ylabel( PASS PERCENTAGE")
plt.title(' ar Graph For Result Analysis")
glt.sho()
ar Graph For Rest Analysis
3
é
6
3
‘
3
&
0
Prycs Gemsty Hn Bogy Compute
SUBECTS WME#15. For the Data frames created above, analyze and plot appropriate charts
itle and legend.
import natplotlib.pyplot as plt
inport nunpy as np
S=[‘tst', ‘2nd’ ,'3rd"]
‘oan armeetlint))
plt.bar(x,per_sc, label="Science’ jnidth+8,25,colon="green')
plt.bar(x+.25, per_con, label’ connerce’ ,width=2.25, color="red")
plt.ban(x+.58,per_hun, label='Hunanities'jwidthe8.25, color=' gold’)
plt.xticks(x,5)
plt.xlabel(‘Position')
plt.ylabel( ‘Percentage’ )
plt.title('Bar Graph For Result Analysis")
plt. legend()
plt. show()
Bar Graph For Result Analysis
is
Position#16. Take data of your interest from an open source (e.g. data.gov.in), aggregate
and summarize it. Then plot it using different plotting functions of the Matplotlib
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("E:\census.csv")
print (df)
S.No. State/UT Total Population of other
1 Andaman & Nicobar Islands 47
2 Andhra Pradesh 43769
3 Apunachal Pradesh 495
4 Assan 11374
5 Bihar 40827
6 Chandigarh 142
7 Chhattisgarh 6591,
8 Dadra & Nagar Haveli 43
9 Danan & Diu 59
10 Goa 398
rr Gujarat aasaa
2 Haryana 2422
2B Himachal Pradesh 2051
14 Jammu & Kashnir 4137
15 Jharkhand 13463
16 Karnataka 20266
7 Kerala 3002
18 Lakshadweep 2
19 Madhya Pradesh 29397
28 Maharashtra 49891
a Manipur 1343
2 Meghalaya 627
2B Mizoram 166
2 Nagaland 398
25 NCT of Delhi, 4213,
26 Odisha 20332
2 Puducherry 252
28 Punjab 10243
29 Rajasthan 16517
30 Sikkim 126
31 Tamil Nadu 22364
32 Tripura 833
33 Uttar Pradesh 137465
34 Uttarakhand 4555
35 West Bengal 30349
35 Total Total 487803inport pandas as pd
inport natplotlib.pyplot as plt
5.81")
lation of other’). head(6))
plt.Legend()
pltshoi()
‘2011 Census Data
Phondeh
Anda ND Andaman Nicobar ands
A ooh Pradesh
a aca Pres
san
fie
Anda LS Oa
AealPh gan#17. Create a student table with the student id, name, and marks as att
where the student id is the primary key.
#18. Insert the details of a new student in the above table.
Pena
Sera
eae
eee iar
7#20. Use the select command to get the details of the students with marks
more than 80.
Bi ULC
#21. Create a new table (order ID, customer Name, and order Date) by joining
two tables (order ID, customer ID, and order Date) and (customer ID, customer
ysql> select™* from orders;
|
| 2020-04-0:
| 2019-01-0:
r
AUSTRALIA |
mystT> create table orderdetails as select orderid custonernane,orderdate
~> fron orders custoner where orders custoneridecustoner.custoner'id:
ysql> select * from orderdetails;
mene gene
“+
| orderid ! _custonername 1 orderdate |
+
| 2020-10-10 |
| 2020-04-05 |
| 2019-01-01 |
+#22. Create a foreign key in one of the two tables mentioned above
yysql> alter table orders add foreign key(customerid) references customer(custonerid);
ery OK, 3 rons affected (1.22 sec)
#23. Find the min, max, sum, and average of the marks in a student marks table.
410 4951805 451.2500
#24, Find the total number of customers from each country in the table
(customer ID, customer Name, country) using group by.
hrysal> select country,count(#) “TOTAL CUSTONER" from customer group by country;
| country | TOTAL CUSTONER |
| AUSTRALIA |
| INDIA |#25. Create a new table (name, date of birth) by joining two tables (student id,
name) and (student id, date of birth).
mysq1> select * from student;
peers += +
| studentia | name |
2] SACHIN
2 | amrr
2 rows in set CO.01 secd
mysq1> select * from studentbirth;
Studentid | dob i
a] 198) iz
2 | 198: 20
rows in set CO.00 secd
mysql> create table stu2 as select name,dob from student,studentbirth
=> where student.studentid=studentbirth .studentid;
Query ok, 2 rows affected (0.37 sec)
Records:'2 Duplicates: 0 Warnings: 0
mysql> select * from stu2;
+ +
| name — | dob |
| SACHIN | 1982-06-17 |
| AMIT | 1981-05-20 |
+ +
2 rows in set (0.00 sec)
#26, Write a SQL query to order the (student ID, marks) table in descending order
of the marks.Long time ago, people who sacrificed their
sleep, family, food, laughter and other
luxuries of life were called SAINTS.
ot eae La moe De)
PROGRAMMERS
Thank You
WTP