0% found this document useful (0 votes)
38 views28 pages

Class Xii Ip Practical File Ankit

The program creates a dataframe containing population, hospital, and school data for 3 cities - Delhi, Mumbai, and Kolkata. It displays the hospital and school columns. Another program creates a similar dataframe using a dictionary with city names as keys and population, hospital, and school data as nested dictionaries. It also displays the hospital and school columns.

Uploaded by

neelamjk01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views28 pages

Class Xii Ip Practical File Ankit

The program creates a dataframe containing population, hospital, and school data for 3 cities - Delhi, Mumbai, and Kolkata. It displays the hospital and school columns. Another program creates a similar dataframe using a dictionary with city names as keys and population, hospital, and school data as nested dictionaries. It also displays the hospital and school columns.

Uploaded by

neelamjk01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

KENDRIYA

VIDYALAYA
NO.2 ,DMW PATIALA .

PRACTICAL FILE

SESSION:2020-2021
CLASS–XII(I n f o r m a t i c P r a c t i c e s )
(PYTHON)

Submitted By: Submitted To:

Ms. Manisha puri


INDEX
S.N Program Sign. Of
o.
1 Write a program to create an empty series.
2 Write a program to create a series showing section names and contribution
made by them using list.
3 Number of students in class 11 and 12 in three streams('sci','comm','arts')
are stored in two series C11 AND 12. Write a program to find total number
of students in class 11 and 12 stream wise.

4 Write a program to arrange the element of a series with values 13,9,12,78


in ascending order.
5 Write code to display those element of series which are less than 5000 from a
series that stores the areas.
6 Write a program to display number of rows in series.
7 Write a program to display first two rows and last two rows of a series.
8 Write a program to create a series using three different words "python", 'is,
'a' ,'language’
9 Write a program to create a series showing the section names and
contribution made by them using DICTIONARY.

10 WRITE A PROGRAM TO CREATE A SERIES USING AN NDARRAY THAT


HAS 5 ELEMENTS IN THE RANGE 24 TO 64
11 Write a program to create dataframe for following and display column
hospital and school using dictionary

Population hospital school

Delhi 100000 200 8000

Mumbai 1200000 500 10000

Kolkatta 230000 150 7000

12 Write a program to create dataframe for following:( using nested list)

A B C

0 1 2 3

1 4 5 6
13 Write a program to display total number of rows and columns in following
Data frame game

G1 G2 G3

0 101 105 106

1 400 500 600

2 300 50 80
14 Write a program to change index values 0,1,2 to M1,M3,M4 in following
dataframe game

G1 G2 G3

0 101 105 106

1 400 500 600

2 300 50 80
15 Write a program to display those whose total score are more than 80 in following
dataframe

Name Score

0 Anil 67

1 Sagar 89

2 sunil 90

3 Aman 56
16 Q2 Create a line chart representing following data:

App name Price

FUN RUN 60

ANGRY BIRD 50

TEEN TITAN 90

MARVEL COMICS 120

COLOR ME 150

X- AXIS SHOULD BE “APP NAME” Y- AXIS SHOULD BE PRICE


17 Draw a line chart to represent sales data of various models of cars in
18 Draw a bar chart representing population of different cities. Colour
a month.
of bar should be green. Xlabel cities and ylabel population
19 Your school sports team have played number of matches in past year as given:

‘football’ = 10 matches ‘cricket’ = 13 matches, ‘badminton’ = 7 matches

‘tt’ = 9 matches, ‘squash’ = 3 matches

Write code to plot a horizontal bar chart with different colours.


20 SQL Queries
1 Write a program to create an empty series.

import pandas as pd

s1 = pd.Series()

print(s1)

O/P

Series([], dtype: float64)


2 Write a program to create a series showing section names and contribution made by
them using list.

import pandas as pd

D = {'A':3500,'B':1200,'C':2300,'D':1500}

S3 = pd.Series(data = D)

print(S3)

O/P
A 3500

B 1200

C 2300

D 1500
3.Number of students in class 11 and 12 in three streams('sci','comm','arts') are stored in
two series C11 AND 12. Write a program to find total number of students in class 11 and
12 stream wise.

import pandas as pd

N11 = [24,45,67]

N12 = [56,67,89]

S = ['sci','comm','arts']

S11 = pd.Series(data = N11,index = S)

S12 = pd.Series(data = N12,index = S)

print(S11)

print(S12)

print(S11+S12)

O/P

dtype: int32

sci 24

comm 45

arts 67

dtype: int64

sci 56

comm 67

arts 89

dtype: int64

sci 80

comm 112

dtype: int64
arts 156

dtype: int64
4. Write a program to arrange the element of a series with values 13,9,12,78 in
ascending order.

import pandas as pd
l=[13,9,12,78]
S = pd.Series(data = L)
print(S)
print(S.sort_values())

O/P

dtype: int64

0 13

1 9

2 12

3 78

dtype: int64

1 9

2 12

0 13

3 78

dtype: int64
5. Write code to display those element of series which are less than 5000 from a series that
stores the areas.
import pandas as pd

A = [1000,100,345,6000]

S2 = pd.Series(data = A)

print(S2[S2<5000])

O/P

0 1000

1 100

2 345

dtype: int64
6 Write a program to display number of rows in series.
import pandas as pd
a =[1,6,7,8]
s=pd.Series(a)
print(s.shape)
O/P
y
(4,)
7 Write a program to display first two rows and last two rows of a series.

import pandas as pd
l=[12,34,56,78]
a=pd.Series(data=l)
print(a.head(2))
print(a.tail(2))
O/P
0 12
1 34
dtype: int64
2 56
3 78
dtype: int64
8 Write a program to create a series using three different words "python", 'is, 'a' ,'language’

import pandas as pd

L = ["python", 'is', 'a' ,'language']

S5 = pd.Series(data = L)

print(S5)

O/P

dtype: int64

0 python

1 is

2 a

3 language
9 Write a program to create a series showing the section names and contribution made
by them using DICTIONARY.

import pandas as pd

D = {'A':3500,'B':1200,'C':2300,'D':1500}

S3 = pd.Series(data = D)

print(S3)

O/P
A 3500

B 1200

C 2300

D 1500
10 WRITE A PROGRAM TO CREATE A SERIES USING AN NDARRAY THAT HAS 5
ELEMENTS IN THE RANGE 24 TO 64

import numpy as np

import pandas as pd

n = np.linspace(24,64,5)

S6 = pd.Series(data = n)

print(S6)

O/P

dtype: object

0 24.0

1 34.0

2 44.0

3 54.0

4 64.0
11 Write a program to create dataframe for following and display column hospital and
school using dictionary

Population hospital school

Delhi 100000 200 8000

Mumbai 1200000 500 10000

Kolkatta 230000 150 7000

import numpy as np

import pandas as pd

p= [100000,200,8000]

h = [200,500,150]

s = [8000,10000,7000]

d = {'population':p,'hospital':h,'school',s}

df1 = pd.DataFrame(d, index = [‘Delhi’,’Mumbai’,’Kolkatta’)

print(df1)

o/p

population hospital school

Delhi 100000 200 8000

Mumbai 200 500 10000

Kolkatta 8000 150 7000

or

using dictionary only


import numpy as np

import pandas as pd

d1 = {'population':
{'Delhi':100000,'Mumbai':1200000,'Kolkatta':230000}

,'hospital':{'Delhi':200,'Mumbai':500,'Kolkatta':150},

'school':{'Delhi':8000,'Mumbai':10000,'Kolkatta':7000}}

df2 = pd.DataFrame(d1)

print(df2)
12 Write a program to create dataframe for following:( using nested list)

A B C

0 1 2 3

1 4 5 6

import numpy as np

import pandas as pd

L = [[1,2,3],[4,5,6]]

DF2 = pd.DataFrame(L,index=[0,1] columns = [‘A’,’B’,’C’])

print(DF2)

o/p

A B C

0 1 2 3

1 4 5 6
13 Write a program to display total number of rows and columns in following
Data frame game

G1 G2 G3

0 101 105 106

1 400 500 600

2 300 50 80

import pandas as pd
game={'G1':[101,400,300],'G2':[105,500,50],'G3':[106,600,80]}
d=pd.DataFrame(game)
print(d.shape)
o/p
(3, 3)
14 Write a program to change index values 0,1,2 to M1,M3,M4 in following dataframe game

G1 G2 G3

0 101 105 106

1 400 500 600

2 300 50 80

import pandas as pd
game={'G1':[101,400,300],'G2':[105,500,50],'G3':[106,600,80]}
d=pd.DataFrame(game)
d.index=['M1','M3','M4']
print(d)
o/p
G1 G2 G3
M1 101 105 106
M3 400 500 600
M4 300 50 80
15 Write a program to display those whose total score are more than 80 in following dataframe
Name Score

0 Anil 67

1 Sagar 89

2 sunil 90

3 Aman 56

import pandas as pd
d={'NAME':['Anil','Sagar','Sunil','Aman'],'SCORE':[67,89,90,56]}
A=pd.DataFrame(d)
sh=A['SCORE']>=80
print(A[sh])
o/p
NAME SCORE
1 Sagar 89
2 Sunil 90
16 Q2 Create a line chart representing following data:

App name Price

FUN RUN 60

ANGRY BIRD 50

TEEN TITAN 90

MARVEL COMICS 120

COLOR ME 150

X- AXIS SHOULD BE “APP NAME” Y- AXIS SHOULD BE PRICE


import matplotlib.pyplot as plt
appname=['funrun','angrybird','teentitan','marvelcomics','colorme']
price=[60,50,90,120,150]
plt.xlabel('appname')
plt.ylabel('price')
plt.plot(appname,price,'c',marker='h')
plt.show()
o/p
17 Draw a line chart to represent sales data of various models of cars in a month.
import matplotlib.pyplot as plt
sales=[120000,400000,500000,400000]
model=['alto','innova','kreta','dzire']
plt.xlabel('model')
plt.ylabel('sales')
plt.plot(model,sales)
plt.show()
o/p
18.Draw a bar chart representing population of different cities. Colour of bar
should be green. Xlabel cities and ylabel population
import matplotlib.pyplot as plt
p=[200000,400000,100000]
c=['bombay','delhi','chandigarh',]
plt.xlabel('c')
plt.ylabel('p')
plt.plot(c,p)
plt.show()
o/p
19 Your school sports team have played number of matches in past year as given:

‘football’ = 10 matches ‘cricket’ = 13 matches, ‘badminton’ = 7 matches

‘tt’ = 9 matches, ‘squash’ = 3 matches

Write code to plot a horizontal bar chart with different colours.


import matplotlib.pyplot as plt
game = ['football','cricket','badminton','tt','squash']
matches = [10,13,7,9,3]
plt.barh(game,matches, color = ['c','r','b','g','y'])
plt.ylabel("GAMES")
plt.xlabel("matches played")
plt.show()
o/p
20 . Binary operation on two dataframes.
import pandas as pd
d1={'score':[12,88,45,67],'marks':[34,78,98,56]}
d2={'score':[23,54,67,44],'marks':[34,45,56,22]}
df1=pd.DataFrame(d1)
df2=pd.DataFrame(d2)
print("first data frame")
print(df1)
print("second data frame")
print(df2)
print("sum is ",df1+df2)
o/p
first data frame
score marks
0 12 34
1 88 78
2 45 98
3 67 56
second data frame
score marks
0 23 34
1 54 45
2 67 56
3 44 22
sum is score marks
0 35 68
1 142 123
2 112 154
3 111 78
import pandas as pd
d1={'score':[12,88,45,67],'marks':[34,78,98,56]}
d2={'score':[23,54,67,44],'marks':[34,45,56,22]}
df1=pd.DataFrame(d1)
df2=pd.DataFrame(d2)
print(df1)
print(df2)
print(df1-df2)
o/p
score marks
0 12 34
1 88 78
2 45 98
3 67 56
score marks
0 23 34
1 54 45
2 67 56
3 44 22
score marks
0 -11 0
1 34 33
2 -22 42
3 23 34
import pandas as pd
d1={'score':[12,88,45,67],'marks':[34,78,98,56]}
d2={'score':[23,54,67,44],'marks':[34,45,56,22]}
df1=pd.DataFrame(d1)
df2=pd.DataFrame(d2)
print(df1)
print(df2)
print(df1*df2)
o/p
score marks
0 12 34
1 88 78
2 45 98
3 67 56
score marks
0 23 34
1 54 45
2 67 56
3 44 22
score marks
0 276 1156
1 4752 3510
2 3015 5488
3 2948 1232

You might also like