Ip Final File
Ip Final File
First and foremost, I would like to thank my teacher Mrs.Gayatri Ghadiali for
their continuous guidance, support, and encouragement throughout the practical
sessions. Their expertise and insights were invaluable in understanding the
concepts and completing the exercises.
I am also thankful to my classmates for their cooperation and for sharing ideas,
which greatly enhanced my learning experience.
Lastly, I would like to thank my family for their constant support and
motivation during the preparation of this file.
NAME- MAITRI VIJAYKUMAR PATEL
CLASS-XII SCI
SUBJECT-INFORMATICS PRACTICES
CODE:
import numpy as np
import pandas as pd
ar=np.arange(35,70,7)
index=ar*3
s=pd.Series(ar,index=index)
print(s)
OUTPUT:
Q:4 Create a Series that stores the area of some states in km 2.Given Series has
been created like this:
S1=pd.Series([34567, 890, 450, 67892, 34677, 78902, 256711, 678291,637632,
25723, 2367, 11789,345, 256517])
i) Write a code to find out the biggest and smallest areas in given Series.
ii) Change the Index values to alphabets a to n.
iii) Retrieve and print first three elements.
iv) Retrieve and print alternate elements, starting from index’b’.
CODE:
import pandas as pd
s1=pd.Series([34567, 890, 450, 67892, 34677, 78902, 256711, 678291,637632,
25723, 2367, 11789,345, 256517])
print(s1)
#i
a=s1.max()
b=s1.min()
print('biggest area in given series',a)
print('smallest area in given series',b)
#ii
l=[]
for i in range (97,111):
l.append(chr(i))
s1.index=l
print(s1)
#iii
print('first 3 values are:')
print(s1.head(3))
#iv
print('alternate elements from b are:')
print(s1['b'::2])
OUTPUT:
i:
ii:
iii:
iv:
Q:5 Four Series objects stores the sales amount of 10 salesmen in four Quarters.
Salesman code form the index of these Series objects. The 4 series objects have
the same indexes.
Calculate the final fixed sales amount obtained by salesmen as per following
formula:
Finalsales=25% Qtr1sales+ 25% Qtr2sales+25% Qtr3sales+25% Qtr4sales
Store the finalsales in another series object.
CODE:
import pandas as pd
ind=['s1','s2','s3','s4','s5','s6','s7','s8','s9','s10']
qtr1=pd.Series([900,980,800,340,567,977,234,931,875,320],index=ind)
qtr2=pd.Series([670,800,540,340,780,900,865,399,945,200],index=ind)
qtr3=pd.Series([789,911,409,569,678,921,400,789,390,764],index=ind)
qtr4=pd.Series([890,467,987,234,653,916,420,766,550,882],index=ind)
final_sales=qtr1*25/100+qtr2*25/100+qtr3*25/100+qtr4*25/100
print(final_sales)
OUTPUT:
Q:6 i) Generate a Dataframe‘case’ Using Dictionary having the following
details
CODE:
import pandas as pd
a={'ID':100,'city':'Delhi','cases':30000,'death':5005}
b={'ID':110,'city':'Mumbai','cases':40000,'death':2060}
c={'ID':120,'city':'Chennai','cases':25000,'death':5060}
d={'ID':100,'city':'Delhi','cases':30000,'death':5005}
l1=[a,b,c,d]
case=pd.DataFrame(l1)
print(case)
#1 maximum cases:
print('(i) city having max case:')
x=case['cases'].idxmax()
print(case.loc[x,'city'])
OUTPUT:
Q:7 Use the Dataframe ‘case’ , plot a multiple line chart to display cases and
death values. Properly label it and also add legend.
CODE:
import pandas as pd
import matplotlib.pyplot as plt
a={'ID':100,'city':'Delhi','cases':30000,'death':5005}
b={'ID':110,'city':'Mumbai','cases':40000,'death':2060}
c={'ID':120,'city':'Chennai','cases':25000,'death':5060}
d={'ID':130,'city':'Surat','cases':35000,'death':1099}
l1=[a,b,c,d]
case=pd.DataFrame(l1)
x=case.city
y=case.cases
y1=case.death
plt.plot(x,y,label='cases')
plt.plot(x,y1,label='death')
plt.xlabel('city')
plt.ylabel('cases and death')
plt.title('comparison of case and death in different cities')
plt.legend()
plt.show()
OUTPUT:
Q:8 Create the following DataFrame Sales containing year wise sales figures for
five sales persons in INR. Use the years as column labels, and sales person
names as row labels.
2014 2015 2016 2017
Madhu 100.5 12000 20000 50000
Kusum 150.8 18000 50000 60000
Kinshuk 200.9 22000 70000 70000
Ankit 30000 30000 100000 80000
Shruti 40000 45000 125000 90000
import pandas as pd
a={2014:
{'Madhu':100.5,'Kusum':150.8,'Kinshuk':200.9,'Ankit':30000,'Shruti':40000},20
15:
{'Madhu':12000,'Kusum':18000,'Kinshuk':22000,'Ankit':30000,'Shruti':45000},
2016:
{'Madhu':20000,'Kusum':50000,'Kinshuk':70000,'Ankit':100000,'Shruti':125000
},2017:
{'Madhu':50000,'Kusum':60000,'Kinshuk':70000,'Ankit':80000,'Shruti':90000}}
sales=pd.DataFrame(a)
print(sales)
#1 row labels
print('row labels of sales are')
print(sales.index)
print()
#2 column labels
print('column labels of sales are')
print(sales.columns)
print()
#3 dtype of each column
print('dtypes of sales are')
print(sales.dtypes)
print()
#4 dimensions,shape,size,value
print('dimensions:',sales.ndim)
print('shape:',sales.shape)
print('size:',sales.size)
print('values:',sales.values)
#5 last two rows of sales
print(' Last Two Rows:')
print(sales.tail(2))
print()
#6 first two columns of sales
print(' First Two Columns Of Sales:')
print(sales.loc[:,2014:2015])
OUTPUT:
Q:9 Use the DataFrame ‘Sales’ created in Question 8 above to do the
following:
a) Change the DataFrame Sales such that it becomes its transpose.
b) Display the sales made by all sales persons in the year 2017.
c) Display the sales made by Madhu and Ankit in the year 2015 and 2017.
d) Display the sales made by Shruti 2016.
CODE:
import pandas as pd
a={2014:
{'Madhu':100.5,'Kusum':150.8,'Kinshuk':200.9,'Ankit':30000,'Shruti':40000},20
15:
{'Madhu':12000,'Kusum':18000,'Kinshuk':22000,'Ankit':30000,'Shruti':45000},
2016:
{'Madhu':20000,'Kusum':50000,'Kinshuk':70000,'Ankit':100000,'Shruti':125000
},2017:
{'Madhu':50000,'Kusum':60000,'Kinshuk':70000,'Ankit':80000,'Shruti':90000}}
sales=pd.DataFrame(a)
print(sales)
#1 transpose of sales
print('Sales As Transpose:')
print(sales.T)
print()
#2 sales in 2017
print('The sales made by all sales persons in the year 2017:')
print(sales[2017])
print()
#3 sales made by Madhu and Ankit in the year 2015 and 2017
print('Sales made by Madhu and Ankit in the year 2015 and 2017:')
print(sales.loc[['Ankit','Madhu'],[2015,2017]])
print()
OUTPUT:
Q:10Use the DataFrame ‘Sales’ created in Question 8 above to do the
following:
a) Delete the data for the year 2014 from the DataFrame Sales.
b) Delete the data for sales man Kinshuk from the DataFrame Sales.
c) Change the name of the salesperson Ankit to Vivaan and Madhu to Shailesh.
d) Update the sale made by Shailesh in 2018 to 100000.
CODE:
import pandas as pd
a={2014:
{'Madhu':100.5,'Kusum':150.8,'Kinshuk':200.9,'Ankit':30000,'Shruti':40000},20
15:
{'Madhu':12000,'Kusum':18000,'Kinshuk':22000,'Ankit':30000,'Shruti':45000},
2016:
{'Madhu':20000,'Kusum':50000,'Kinshuk':70000,'Ankit':100000,'Shruti':125000
},2017:
{'Madhu':50000,'Kusum':60000,'Kinshuk':70000,'Ankit':80000,'Shruti':90000}}
sales=pd.DataFrame(a)
print(sales)
OUTPUT:
Q:11 Create a dictionary using the following data. Use this dictionary to create a
DataFrame Sales2.
2018
Madhu 160000
Kusum 110000
Kinshuk 500000
Ankit 340000
Shruti 900000
Check if Sales2 is empty or it contains data.
CODE:
import pandas as pd
a={'2018':
{'Madhu':160000,'Kusum':110000,'Kinshuk':500000,'Ankit':340000,'Shruti':900
000}}
sales2=pd.DataFrame(a)
print(sales2)
print('is sales2 empty?',sales2.empty)
OUTPUT:
OUTPUT:
Q:13 Create the given dataframe ‘shop’ using Series method:
Appliance_name Discount Price
0 Refrigerator 15 19800
1 Smart phone 20 22300
2 Television 22 12900
3 Air conditioner 15 23500
4 Washing Machine 18 18900
5 Washing Machine 15 20110
Write the python command to perform following operations:
I] Add a new Electronics item named ‘Television’, with discount 12 having
price 35600.
II] Rename the column name Appliance_name to Itemname.
III] To find the minimum price of Items.
IV] Display Itemname and price for all Items having price more
than20000.
V] Change the discount value of smart phone to 25.
VI] Add a new column ‘NETPRICE’ having value as price-discount.
VII] Display Itemnameandnetprice columns.
CODE:
import pandas as pd
appliance_name= pd.Series(['Refrigerator', 'Smart phone', 'Television', 'Air
conditioner',
'Washing Machine', 'Washing Machine'])
discount= pd.Series([15, 20, 22, 15, 18, 15])
price=pd.Series([19800, 22300, 12900, 23500, 18900, 20110])
shop=pd.DataFrame({'Appliance_name': appliance_name,'Discount':
discount,'Price':
price})
print(shop)
print()
#1
print('Add a new Electronics item named ‘Television’, with discount 12 having
price 35600:')
print()
shop.loc[len(shop)]=['Television',12,35600]
print(shop)
print()
#2
print('Rename the column name Appliance_name to Itemname:')
print()
shop.rename(columns={'Appliance_name':'Itemname'},inplace=True)
print(shop)
print()
#3
print('The minimum price of Items:')
print()
print(shop['Price'].min())
print()
#4
print('Display Itemname and price for all Items having price more than 20000:')
print()
df=shop[shop['Price']>20000]
df.loc[:,['Itemname','Price']]
print(df)
#5
print('Change the discount value of smart phone to 25:')
print()
shop.at[1,'Discount']=25
print(shop)
print()
#6
print('Add a new column ‘NETPRICE’ having value as price-discount:')
print()
shop['Net Price']=shop['Price']-shop['Discount']
print(shop)
print()
#7
print('Display Itemname and netprice columns:')
print()
print(shop.loc[:,['Itemname','Net Price']])
OUTPUT:
Q:14 Create a Criciket.csv file. Using dataframecricketdf perform the
following.
SNO Batsman Test ODI T20
1 ViratKohli 3543 2245 1925
2 AjinkyaRehane 2578 2165 1853
3 Rohit Sharma 2280 2080 1522
4 ShikharDhawan 2158 1957 1020
5 Hardik Pandya 1879 1856 980
a) Find the maximum Score in Test.
b) Find the average score of ODI.
c) Find the Total of T20 score.
d) Find the total number of batsman played.
CODE:
import pandas as pd
x=[[1,'virat kholi',3543,2245,1925],
[2,'ajinkya rehene',2575,2165,1853],
[3,'rohit sharma',2280,2080,1522],
[4,'shikhar dhawan',2158,1957,1020],
[5,'hardik pandya',1879,1856,980]]
cricket=pd.DataFrame(x,columns=['sno','batsman','test','odi','t20'])
print(cricket)
cricket.to_csv('E:\\pract file\\cricket.csv')
#A
print('maximum score in test is',(cricket.test.max()))
#B
print('avg score of odi',(cricket['odi'].mean()))
#C
print('total of t20 score',(cricket['t20'].sum()))
#D
print('total.no of batsman played',(cricket['batsman'].count()))
OUTPUT:
Q:15 Given a DataFrame namely DF1 as shown (fruit names are row labels)
write code for the following:
Colour Count Price
Apple Red 3 120
Apple Green 9 110
Pear Red 25 125
Pear Green 26 150
Lime Green 99 70
1) Find all rows with the label “apple”. Extract all columns
2) List fruits with count more than 25.
3) List single True or False to signify if all prices are more than 100 or not.
4) List only the columns count and price using loc.
5) List only columns 0 and 2 (column indexes) using iloc.
6) List only rows with the label ‘Apple’ and ‘Pear’ using loc.
7) List only rows 1,3,4 using iloc
CODE:
import pandas as pd
import numpy as np
x=[['red',3,120],['green',9,110],['red',25,125],['green',26,150],['green',99,70]]
DF1=pd.DataFrame(x,columns=['colour','count','price'],index=['apple','apple','pe
ar','pear','lime'])
print(DF1)
#A
print('all rows with lable as apple:')
print()
print(DF1.loc['apple',:])
print()
#B
print('fruits with count more than 25:')
print()
print(DF1[DF1['count']>25])
print()
#C
print('true or false if prices are more than 100:')
print()
print(DF1['price']>100)
print()
#D
print('only column count and price with loc:')
print()
print(DF1.loc[:,'count':'price'])
print()
#E
print('only columns 0 and 2 using iloc:')
print()
print(DF1.iloc[:,0:3:2])
print()
#F
print('only rows with label apple and pear using loc:')
print()
print(DF1.loc[['apple','pear'],:])
print()
#G
print('only rows 1,3,4 using iloc:')
print()
print(DF1.iloc[[1,3,4],:])
OUTPUT:
Q:16Given the following set of Data. Weight measurements for 16 small orders
of french-fries (in grams)
78 72 69 81 63 67 65 75 79 74 71 83 71 79 80 69
a) Create a horizontal histogram from the above data.
b) Create a step type of histogram from the above data.
c) Create a cumulative histogram from the above data.
CODE:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
weight=[78,72,69,81,63,67,65,75,79,74,71,83,71,79,80,69]
plt.figure(figsize=(15,10))
#A
plt.hist(weight,bins=5,orientation='horizontal')
plt.xlabel('weight(grams)')
plt.ylabel('order')
plt.title('horizontal histogram of FrenchFries order weights')
plt.show()
#B
plt.hist(weight,bins=5,histtype='step',color='blue')
plt.xlabel('Weight(grams)')
plt.ylabel('Frequency')
plt.title('Step Type Histogram of FrenchFries Order Weights')
plt.show()
#C
plt.hist(weight,bins=5,cumulative=True,color='pink')
plt.xlabel('Weight(grams)')
plt.ylabel('Cumulative Frequency')
plt.ylabel('Cumulative Frequency')
plt.title('Cumulative Histogram of FrenchFries Order Weights')
plt.show()
OUTPUT:
Q:17Using dataframe created ‘Cricket .csv’, Plot a multiple bar graph to
compare TEST,ODI and T20 scores. Label graph properly.
CODE:
import pandas as pd
import matplotlib.pyplot as plt
cricketdf=pd.read_csv('E:\\pract file\\cricket.csv',index_col=0)
print(cricketdf)
cricketdf.plot(kind='bar')
x=cricketdf['test']
y=cricketdf['odi']
z=cricketdf['t20']
plt.title('comparison of scores of matches')
plt.xlabel('matches')
plt.ylabel('scores')
plt.xticks([0,1,2,3,4],cricketdf['batsman'])
plt.legend()
plt.show()
OUTPUT:
Q:18 Write code to plot a line graph showing the relation between channel
name and its TRP rating ( 4 channels). Include the titles and formatting of your
choice. The font size of the x and y labels should be 15 and font color should be
green.
CODE:
import pandas as pd
import matplotlib.pyplot as plt
trp=[3.8,4,4.5,4.7]
channels=['sony','colours','zee','sab']
plt.plot(channels,trp)
plt.title('comparison of trp')
plt.xlabel('channels',fontsize=15,color='green')
plt.ylabel('trp',fontsize=15,color='green')
plt.show()
OUTPUT:
Q:19 Suppose a data frame Df1 contains information about student having
columns. Write command to plot a bar graph using plot() method.
CODE:
import pandas as pd
import matplotlib.pyplot as plt
data = {'Name': ['Atul', 'Nilesh', 'Jiya'],'Class': ['IX', 'IX', 'IX'],'Section': ['A', 'B',
'A'],'Height': [163, 167, 164],'Weight': [50, 55, 59]}
df1= pd.DataFrame(data)
df1.index= [1, 2, 3]
df1.index.name='Roll No'
print(df1)
df1.plot(kind='bar')
plt.title('student details')
plt.xlabel('Name')
plt.ylabel('Height/Weight')
plt.xticks([0,1,2],df1['Name'])
plt.show()
OUTPUT:
MYSQL QUERIES
Consider a table LoanAccount with the following data.
Accn Cust_name Loan_Amount Installment Int_rate Start_dateInterest
o
1 R. K.Gupta 300000 36 12.00 2009-07-19
2 S.P.Sharma 500000 48 10.00 2008-03-22
3 K.P.Jain 300000 36 Null 2007-03-08
4 M.P.Yadav 800000 60 10.00 2008-06-12
5 S.P.Sinha 200000 36 12.50 2010-01-03
6 P.Sharma 700000 60 12.50 2008-06-05
7 K.S. Dhall 500000 48 Null 2008-03-05
4. Display the details of all the loans started after 31-12-2008 for which number
of installment are more than 36.
5. Display the details of all the loans whose rate of interest is in the range 11%
to 12%. (use Between)
6. Display the Accno, Cust_name in uppercase and Loan_Amount for all the
loans for which Cust_name ends with ‘a’.
7.Display the details of all the loans in the descending order of their Start_date.
8. Set the interest rate 11.50% for all the loans for which interest is Null.
9. To find the customer name and minimum loan amount which started in year
2009.
10.Change column name start_dateinterest to startdate
11. To count total number of customers for which interest rate is Null.
7 Use the Dataframe ‘case’, plot a multiple line chart to display cases and death values.
Properly label it and also add legend.
8 Create the DataFrame Sales containing year wise sales figures for five sales persons in
INR. Use the years as column labels, and sales person names as row labels. Perform the
given operations.
9 Use the DataFrame ‘Sales’ and perform the given operations on it.
10 Use the DataFrame ‘Sales’ created in Question 8 and perform the given operations on
it.
11 Create a dictionary using the given data. Use this dictionary to create a DataFrame
Sales2. Write command to check if Sales2 is empty or it contains data.
12 Create a csv name ‘emp.csv’ , convert it in dataframe and write a command to perform
given operations.
13 Create the given dataframe ‘shop’ using Series method, and write commands to
perform the given operations.
14 Create a Criciket.csv file,using dataframecricketdfand perform the following given
operations.
15 Given a DataFrame namely DF1 (fruit names are row labels) write code to perform the
given operations.
16 Given the following set of Data of Weight measurements for 16 small orders of french-
fries (in grams) , Create a horizontal histogram , Create a step type of histogram ,Create
a cumulative histogram.
17 Using dataframe created ‘Cricket .csv’, Plot a multiple bar graph to compare TEST,ODI
and T20 scores. Label graph properly.
18 Write code to plot a line graph showing the relation between channel name and its TRP
rating ( 4 channels). Include the titles and formatting of your choice. The font size of the
x and y labels should be 15 and font color should be green.
19 Creae data frame Df1 contains information about student’s,Write command to plot a
bar graph using plot() method.
20 MySQL queries to create table and to perform given operations on it.
Practical Work
CERTIFICATE
This is to certify
Mast/Miss____________________________________________
XII
Practical File
School stamp