Ip Final Practical File PDF
Ip Final Practical File PDF
ANIRUDH VISVESVARAN
XII-B
19
2
INDEX
S.NO. PG.NO.
1 Question 1
2 Question 2
3 Question 3
4 Question 4
5 Question 5
6 Question 6
7 Question 7
8 Question 8
9 Question 9
10 Question 10
11 Question 11
3
12 Question 12
13 Question 13
14 Question 14
15 Question 15
16 Question 16
17 Question 17
18 Question 18
19 Question 19
20 Question 20
QUESTION 1
Create the series Vowels , having 5
elements with index ‘a’,’e’,’i’,’o’,’u’ and
all five values set to zero. Check if it is an
empty series.
CODE OF QUESTION 1
import pandas as pd
a=[1,2,3,4,5]
b=['a','e','i','o','u']
vowels=pd.Series(a,index=b)
if vowels.empty==True:
print('The series is empty.')
else:
print('The series is not empty')
QUESTION 2
Set all the values of Vowels(Created in
above question) to 10 and display the
series.Divide all values of vowels by 2 and
display the series.Create another series
vowels1 having 5 elements with labels
‘a’,’e’,’i’,’o’,’u’ having values .Add
vowels and vowels1 and assign the result
to vowels3 .Subtract, multiply and divide
vowels by vowels1 Alter the labels of
vowels1 to [‘A’,’E’,’I’,’O’,’U’]
CODE OF QUESTION 2
import pandas as pd
a=[1,2,3,4,5]
b=['a','e','i','o','u']
vowels=pd.Series(a,index=b)
vowels[:]=10
print (vowels,'\n')
vowels1=pd.Series([6,7,4,1,8],index=['a','e',
'i','o','u'])
vowels3=vowels1+vowels
print(vowels3 , '\n')
print(vowels-vowels1,'\n')
print(vowels*vowels1,'\n')
print(vowels/vowels1,'\n')
vowels1.index=['A','E','I','O','U']
print (vowels1)
OUTPUT OF QUESTION 2
+
QUESTION 3
Create the series MonthDays, from a
numpy array having the no. of days in the
12 months of a year. The labels should be
the month numbers from 1 to 12.
CODE OF QUESTION 3
import pandas as pd
import numpy as np
a=np.array([31,28,31,30,31,30,31,31,30,31,
30,31])
monthdays=pd.Series(a,index=range(1,13))
print(monthdays)
QUESTION 4
Using series created in above questions
(monthdays), write following commands:
Display the names of the months 3 through
7 from the series
Display the series MonthDays in reverse
order.
CODE OF QUESTION 4
import pandas as pd
import numpy as np
a=np.array([31,28,31,30,31,30,31,31,30,31,
30,31])
monthdays=pd.Series(a,index=range(1,13))
print(monthdays[3:8],'\n')
print(monthdays[::-1],'\n')
QUESTION 5
Create the series MTseries, an empty series.
Check if it is an empty series.
Add 5 values in the series
Change the default indexes to 5 multiples
of 7
CODE OF QUESTION 5
import pandas as pd
a=[]
MTseries=pd.Series(a , dtype=object)
if MTseries.empty==True:
print('The series is empty \n')
else:
print('The series is not empty \n')
MTseries=pd.Series(['a','b','c','d','e'] ,
index=range(1,36,7))
print(MTseries)
OUTPUT OF QUESTION 5
QUESTION 6
create a dataframe to hold details of
vegetables with the help of a dictionary.
Dictionary should contain two keys
‘vegetable’ and ‘price’. Value of key1 is a
list holding name of vegetables. And key2
is list of prices.
CODE OF QUESTION 6
import pandas as pd
data={'Vegitables':['onion','potato','pumpki
n'] , 'price(Rs)' : [50,40,35] }
df=pd.DataFrame(data)
print(df)
QUESTION 7
Create a dataframe to print the following
output using 2D dictionary.
year state pop debt
One 2000 Ohio 1.5 16.5
two 2001 Ohio 1.7 16.5
three 2002 Ohio 3.6 16.5
four 2001 Nevada 2.4 16.5
five 2002 Nevada 2.9 16.5
six 2003 Nevada 3.2 16.5
CODE OF QUESTION 7
import pandas as pd
data={'year':['2000','2001','2002','2001','20
02','2003'] ,'state':['ohio','ohio','ohio','nevad
a','nevada','nevada'] ,'pop':[1.5,1.7,3.6,2.4,2.
9,3.2] ,'debt':['16.5','16.5','16.5','16.5','16.5',
'16.5',] }
df=pd.DataFrame(data,index=['one','two','t
hree','four','five','six'])
print(df)
OUTPUT OF QUESTION 7
QUESTION 8
Delete column pop from above dataframe
(q7)
Delete row ‘six’ from above dataframe(q7)
Rename all the columns to
[‘YEAR’,’STATE’,’DEBT’]
Rename row ‘two’ to ‘TWO’
CODE OF QUESTION 8
import pandas as pd
data={'year':['2000','2001','2002','2001','20
02','2003'] ,
'state':['ohio','ohio','ohio','nevada','ne
vada','nevada'] ,
'pop':[1.5,1.7,3.6,2.4,2.9,3.2] ,
'debt':['16.5','16.5','16.5','16.5','16.5','
16.5',] }
df=pd.DataFrame(data,index=['one','two','t
hree','four','five','six'])
print(df.drop('pop',axis=1) , '\n')
print(df.drop('six',axis=0) , '\n')
print(df.rename(columns =
{'year':'YEAR','state':'STATE','debt':'
DEBT'}) , '\n')
print(df.rename(index = {'two':'TWO'}) ,
'\n')
OUTPUT OF CODE 8
QUESTION 9
Create following dataframe :
DF1 DF2
Mark1 Mark2 Mark1 Mark2
0 10 15 0 30 20
1 40 45 1 20 25
2 15 30 2 20 30
3 40 70 3 50 30
CODE OF QUESTION 10
import pandas as pd
dict1={'MARK1':[10,40,15,40] ,
'MARK2':[15,45,13,17]}
dict2={'MARK1':[30,20,25,50] ,
'MARK2':[20,25,30,30]}
DF1=pd.DataFrame(dict1)
print(DF1 , '\n')
DF2=pd.DataFrame(dict2)
print(DF2 , '\n')
print(DF1+DF2)
OUTPUT OF QUESTION 10
QUESTION 11
WA python code to Import data from CSV
to dataframe using offline resource.
File address => C:\CSV\Book1.csv
CODE OF QUESTION 11
import pandas as pd
df=pd.read_csv('C:\CSV\Book1.csv')
print(df)
OUTPUT OF QUESTION 11
QUESTION 12
WA python code to export data from
dataframe to CSV.
CODE OF QUESTION 12
import pandas as pd
d={2015:[34500,45000,50000,39000] ,
2016:[44500,65000,70000,49000] ,
2017:[44500,65000,70000,49000]}
df=pd.DataFrame(d,index=['QTR1','QTR2',
'QTR3','QTR4'])
df.to_csv('C:\\CSV\\book2.csv')
OUTPUT OF QUESTION 12
QUESTION 13
Consider the average heights and weights
of persons aged 8 to 16 stored in the
following two lists:
height =
[121.9,124.5,129.5,134.6,139.7,147.3,152.
4, 157.5,162.6]
weight=
[19.7,21.3,23.5,25.9,28.5,32.1,35.7,39.6,43.
2]
36 37 36
38 39 40
42 41 40
40 41 42
39 40 41
35 34 33
40 38 39
QUESTION 17
Plot a horizontal bar chart holding names
on y axis and their lengths on x axis. Color
of bars should be orange with height=0.25.
label x and y axis.
CODE OF QUESTION 17
import matplotlib.pyplot as plt
y1=[5,7,4,6,5,8]
x1=['ANI','ASW','POOR','VISU','RAG','A
VY']
plt.bar(x1,y1,width=0.25,color='orange')
plt.ylabel('HEIGHT IN FEET')
plt.xlabel('NAMES')
plt.show()
OUTPUT OF QUESTION 17
QUESTION 18
Plot bar chart for student strength analysis
for three consecutive years. Data is stored
as pandas dataframe. Give title of the chart.
Label x and y axis.
CODE OF QUESTION 18
import matplotlib.pyplot as plt
import pandas as pd
df=pd.DataFrame({2019:[41,42,39,37],202
0:[35,36,34,36],2021:[40,39,39,41]} ,index
=['A','B','C','D'])
df.plot(kind='bar')
plt.xlabel("SECTION")
plt.ylabel("STRENGHT")
plt.title("STUDENT STRENGTH
ANALYSIS")
plt.show()
OUTPUT OF QUESTION 18
QUESTION 19
Plot stacked bar chart of Q18.
CODE OF QUESTION 19
import matplotlib.pyplot as plt
import pandas as pd
df=pd.DataFrame({2019:[41,42,39,37],202
0:[35,36,34,36],2021:[40,39,39,41]} ,index
=['A','B','C','D'])
df.plot(kind='bar',stacked=True)
plt.xlabel("sections")
plt.ylabel("strength")
plt.title("students strength analysis")
plt.show()
OUTPUT OF QUESTION 19
QUESTION 20
Plot a histogram for number of students
with their respective weights.
CODE OF QUESTION 20
import matplotlib.pyplot as plt
w=[19,25,30,35,45,55,60]
plt.hist(w,bins=[0,10,20,30,40,50,60],
weights=[20,10,15,35,40,6,8],
edgecolor='red')
plt.show()
OUTPUT OF QUESTION 20
THANK
YOU
OUTPUT OF QUESTION 6
OUTPUT OF QUESTION 4
OUTPUT OF QUESTION 1
QUESTION 16
Visualize weather report for three
consecutive weeks through line plot using
WEATHER.csv. chart title as “Weather
report” give proper labels to axis
36 37 36
38 39 40
42 41 40
40 41 42
39 40 41
35 34 33
40 38 39
CODE OF QUESTION 16
import matplotlib.pyplot as plt
import pandas as pd
df=pd.read_csv('C:\CSV\WEATHER.csv')
df.plot(kind='bar')
plt.title('WEATHER REPORT')
plt.xlabel('WEEKS')
plt.ylabel('TEMPERATURE')
plt.show()
OUTPUT OF QUESTION 16
OUTPUT OF QUESTION 3