Practice Questions (Unsolved)
Practice Questions (Unsolved)
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
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)
no ename sal
A1 101 a 3000
A2 102 b 5000
A3 103 c 8000
A4 104 d 9000
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
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.
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)
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
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