0% found this document useful (0 votes)
43 views

Practice Questions (Unsolved)

Uploaded by

rao821066
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Practice Questions (Unsolved)

Uploaded by

rao821066
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

23

Practice Questions-IV(Unsolved)
output:
the missing statements toget the given
67.Fill
Amport pandas as pd
empno=[101,102, 103,104,105,106,107]
p=pd.Series() #statement 1
(3))#statement 2
print (p.
output
101
1 102
2 103
display last two rows usingtail() from
series P.
68. Write single line python code to
of 1st element using index label value.
69. Fil! the missing statement to print value
import pandas as pd
=[a,'b';c,'d','e'])
s =pd.Series([1,2,3,4,5],index
#retrieve a single element

Its output is as follows


1

70 Give the output


import pandas as pd
s =pd.Series([1,2,3,4,5],index =[a',b','c;d','e'l])
print(s['a','c,d)
11.Give the output
import pandas as pd
name=[Harsh','Arun',' Ankur', Harpahul', Divya'.'Jeet']et te eln e
empno=[101,102,103,104,105,106]
p=pd.Series(name, index=empno)
print (,p[[101,105,106]])

72: Give the output


import pandas as pd
s= pd.Series([1,2,3,4,5], index = ['a','b,'c,'d';'e'])
print (s[0))
print(s['a])
how all
73. Give the output
import pandas as pa
c=[red','green','blue',' pink''black', white']
p=pd.Series(c,index=[r,g;b',p';k, W])
print (p[2) #1
print(p[:2]) #2
print(p[2:])) #3
print(p{2:5]) #4
print(p[1:5:2) #5
print(p[: : 2] #6
Inspire Shiksha
24
print(p[-1]) #7
print(p[::-1]) #8
print(p[-1:-4:-1]) #9
print(p[-1:-5:1]) #10
74. Fill the missing
import pandas as pd statements to get the given output:
rollno=[1,2,3,4,5,6,7]
Fpd.Series( )#statement 1
print (p.head()#statement 2
output
1
1 2
2 3

75. Poonam wants to display first 3


import pandas as pd elements from series S. She wrote the following program:
S=pd.Series([1 0,20,30,40,50],index =[1,2,3,4,5)
print(S.iloc[1:3])
But she did not get the desired result. Rewrite the
get the desired output above program with necessary changes to help

76. Consider the following Series Object, Student


Mishra Commerce
Gupta Arts
Khan Science
Chaddha Commerce
Yadav Arts
i. Write the command which will display the names of students having stream="Arts"
ii. Write the command to name the series as Subject.

6.Arithmetic Operations
You can perform arithmetic operations like addition, subtraction, division, multiplication on two $
ries objects.
The operations are performed only on the matching indexes.
" For all non-matching indexes, NaN (Not a Number) will be returned.
77.Write aprogram to create two series P1and P2 with the following data and give command
P1 and P2

PI P2
A 10 A 100
B 20 B 200
C 30 C 300
D 40 D 400
E 50 500
Ans
import pandas as pd
Inspire Shiksha
80
90. Consider the following
ITEM NO COST
DataFrame, ITEM
101
S000
102 3000
103
4000
) Add newrow with ITEM NO=104 and
(i)Display the cost of ITEM_ N0 103 cost=8000 using | append method
Ans ()1TEM=ITEM.append({ITEM NO':104,'cost':8000},ignore_index=True)
(1) print(TEM.iloc[2,1)

Pyáctice Questions-IV (Unsolved)


91. Write asmall python
code to drop a column
92. Aman wants to "address" from dataframe stud using del
delete coloumn "admno" from
school.drop('admno")
print(school)
But not getting the
school dataframe. He has
written the following code
result. Help Aman to rectify
v93. WNrite a the errors in code.
small python code to
drop a row from
w94. Give the output: dataframe labeled as 0.
import pandas as pd [SP 2019-20]
Diprintc={r(df)ol ':(1,2,3), 'name':('a',;b',' c),
df=pd.DataFrame(Dic) marks'(24,53,66)}
df.insert(loc=1,column='grade',value-['ab';a'])
print(df)
w95. write
command to add
append method
96. Write the
new row in
dataframe df (id,name,price) with
correct
import pandas as pd output on execution of the
following Pandas code: values(110,'xyz',800) using
J97.df-pd.DataFrame([('ODactm',9a3Frame),(Jay',91)],columns=[Name'; Mark'T)
print(df['
thonGagan
Name'])
code tocreated a df but
rename the default index forgot to give the index
98. Fill the values with new index value (A, B,'C).
missing
import pandas as pdstatement to change the values. Create asmall pv
columns name in dataframe to get
the given
print(df) output.
print(df)
81
empno name salary
A1 101 3000
A2 102 5000
A3 103 C 8000
A4 104 d 9000

no ename sal
A1 101 a 3000
A2 102 b 5000
A3 103 c 8000
A4 104 d 9000

99. Give the output


import pandas as pd
Dic={'empno':(101,102,103,104),'name':('a','b','c',' d'),'salary': (3000,5000,8000,9000)}
df-pd.DataFrame(Dic, index=[A1;A2, A3,'A4'])
lowing o df1=df.rename(columns={'name':'ename'})
print(df)
print(df1)
100. Write a program in Python Pandas to create the following DataFrame batsman from a Dictionary:
P20192 B NO Name Scorel Score2
Sunil Pillai 90 80
Gaurav Sharma 65 45
3 Piyush Goel 70 90
4 Kartik Thakur 80 76
Perform the following operations on the DataFrame:
1)Add both the scores of a batsman and assign to column "Total"
2)Display the DataFrame [SP 21]
101. Consider the following DataFrame, classframe
Rollno Name Class Section CGPA Stream
0) ustg Stl Aman IX E 8.7 Science
St2 2 Preeti 8.9 Arts
St3 3 Kartikey IX D 9.2 Science
St4 4 Lakshay X A 9.4 Commerce
Write commands to:
i.Add a new column 'Activity' to the Dataframe
i. Add a new row with values (5, Mridula ,X, F,9.8, Science) [SP 21]
all p 102. Consider the following DataFrame, Book
Title Price
101 ABCof Physics 300
102 Informatics made fun 250
103 Computers are simple 375
Write commands to:
i, Add a new column Year' with the values :(2005,2010,2018)
i. Add a new row with values ("Informatics",350,2020)

Inspire Shiksha
82
103. Consider the following DataFrame,
Friends
Name Hobbies
F101
F102 Bijoy
Abhinav
Swimming
F103 Reading books
Jyotsna
Write Dancing
1. Addcommands
to :
a new column 'Age' at 2
position using insert function with the
ii.(20,17,18)
Change the column name followng values
"Name" to "FName"
104 Consider the
following DataFrame, Teacher
T101 Department
SCIENCE Periods
T102 32
TI03 ENGLISH 30
i. Add a
ii. MATHEMATICS 34
new
Delete the row with values
105. Write a
column
"Departm(" COMPUTER",
ent'
program Python Pandas to
35)
DiFCODE
ctionary: NAME in
create the
10023 Table PRICE following DataFrame
10001
10012 Chair
Sofa
4000
2050
Furniture from a
Perform the following 3500
1)Calulatthee 10%no ofof priceoperat
2)Count and iassign
ons on the
3)Display the DataFrame
106. Write a
columns of to column
DataFrame.DataFrame
"Tax"
Orderld program Python
in
101
102 SalesPerson 40000
Ravi Sales Pandas to create the
103
Perform the
1)To change fthe
Rashmi
Rohan 50000 following DataFrame Order from
ol owi n g 55000 a

splay thethe coiu'Smnales'oper


3)1072)DCihange in athe
tions
3th
on the
name row to(i.e.DatforaFrame Dictionary:
Write a DataFrainme colu'Omns
./
B NO rderld' 'ld' index 2) to
Namepro gram Pyt h on names 2500O
2 Sunil Pillai
Gaurav Sharma 65 90
Pandas
marks to
create the
Piyush Thakur
Goel 80 marks2 fol owing DataFrame stud
Kartik
Performboththethe 70 45
1)Add folowing 80 90 from a
marks oper
of aations on
the
76
student and assiDatganFrtoame Dictonary.
Inspire colShikustmn
2)Display the DataFrame 83

108. Sangeeta
has
She hascreated
name column. a
datafranme with
written the code but columns- name and marks but wants to
[SP 21]
import pandas as pd
getting1some errors, help sangeeta and reciftydisplay
#statement only

st=['NDidathia'Frame(Ist
Af-pd. ,95],('Gur,jecolt,u9mns=[
print (name) #statement 4
109.Give the output
7],(Pah'nulame'',88),'m,['arks')
Divya',721] #statement
#statement 3
2
the errors.

import pandas as pd
df=
pd.DataFrame({('x: [1, 2, 3], y': [4, 5, 6])
df.rename(columns={*: 'A},inplace=True)
print(df)

110 Adataframe df is
empno name salarygiven below:
A1 101
A2 102
3000
A3 103
5000
8000
A4 104 d
9000
Give the output of the
following
(a)print(df.loc['A2':A3,['name','salary']) (b) print(df.iloc[0:2) (c)print(df.iloc[1 :3,2:3])
111. Write a program in
Python Pandas to create the
country population percent
following DataFrame [comptt 21]
IT Italy 61
ES
0-83
Spain 46
0-63
GR
Greece 0-15
FR France 65
0-88
PO
Portugal 10 0-14
Perform the following operations on the
() Display the columns DataFrame:
country and population.
(i) Display all the rows where
(i) Delete the last 2 population is more than 40.
rows.

112.What will be the output of the Python program ?


import pandas as pd [comptt 21]
I-[Apple' Banana', Mango'' Orange','Litchi]
df-pd.DataFrame(l,index-[1,2,3,4,5])
print(df.iloc[1:3])
113 Consider the following DataFrame 'stu'
Admno Firstname Lastname Age Pretest Posttest
1001 Amit Sehgal 87 67
1002 Rohit Malik 89 78
1003 Shyam Bhatia 18 90 84

Inspire Slhiksha
27
Practice Questions-VI(Unsolved)
Nhich attribute is used with Series to
V(a) size (b) len (c) count the total number of NaN values
count (d) count total
[2021-22 Term1]
R5 Given the following twO series P1
and P2
P2
A 100 C 200
B 200 D 400
C 300 E 600
D 400 F 800
E S00 G 1000
Give the output of following commarnd.
print(P2-P1)

86. Given the following Series S1

1 10
2 15
3 30
4 35
5 50
Give the output after execution of the following python statement
print(S1*2)
87 Given the following Series S1 and S2:
S1 S2
A 10 A 80
40 20
C 34 C 74
D 60 D 90
Write the command to find the sum of series S1 and S2 [SP 21]

88. Consider two objects x and y. x is a list whereas y is a Series. Both have values 20, 40,90, 110.
Ahat will be the output of the following two statements considering that the above objects have been
created already
a. print (x*2) b. print(y*2)
Justify your answer [SP 21]
89. Consider the following two series 'A' and 'B' [comptt 21]
A=pd.Series([2,4,6], index-[0,1,2)
B=pd.Series([1,3,5], index=[1,2,3])
() Write the statement to add both the series 'A' and 'B'
(i) Write the statement to multiply two sereis 'A' and 'B'
90,Write a program in Python to create the series of all the alphabets of "Happy" with default index.
Print the first three alphabets.[comptt 21]
91. Which of the following statement is wrong? [2021-22 Term1]
Inspire Shiksha
28
(a) Can't change the
indexthe
(b) We can easily convert of the
list, Series
tuple and dictionary into a series.
(c) ASeries
(d) We can represents a sinale column in memory.
create empty Series.
92. What type of
Amport pandas as error
pa
is
returned by the following statement? [2021-22 Term1]
pa.Series([1,2,3,4]),index-['a ,'b', c])
(a) Value Error (b)
Syntax Error (c) Name Error (d) Logical Error
93. Consider the
import numpy as following
np
code: [2021-22 Term1]
import pandas as pd
L=np. a rray([10,
X=pd.Series(
print(x)
20]) #statement 1
output
0 1000
of the above
code is:
1 8000
What is the correct
(a) d=L*3 (b) statement for the above output in the
data=L**3 (c) L*3 (d) [10,20]**3 following statement-1?
94. What will be the
as output the
import of
pandas
import numpy pd following code?
[2021-22 Term1]

s=pd.Series(data=[31,54,34,89,12,23],dtype=numpy.int)
print(s>50)
0

2
3
4
(a)
false
1 True
False
True
(b)|
54
3 89
|dtype : int64
(c)
0 31

2 34
54
(d)
1
3
True
True
dtype : bool
5 False 3 89
False 4 12

dtype:bool 5 23

95. dtype: int64


Consider the following series
ser=pd.Series([C,¡,
print(ser[4:])
(a)
4 F
5 0
6 R
7 T
8A
(b)
4 F

6 R
7 T
8 A
M";F;o,R,T;A,B,L,E,index=[1,2,3,4,5,6,
(c)
4 F

6 R
7 T
()
5 O
|6 R
7 T
[2021-22 Term1]
7,8,9,1 0,11)

9 B 8 A 8 A
10 L
11E
dtype:object 9 B 9 B
10 L
dtype: object dtype:object 11 E
dtype : object

You might also like