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

Series Worksheet1 3

This document contains questions about pandas series attributes and methods. It asks about size, head, tail, reindex, CSV, dimensionality, creator of pandas, installing pandas, origin of name 'pandas', analyzing data in pandas, package vs library vs language, valid import statements, attributes of data frame, loc and iloc functions, adding rows, setting values to zero, shape of series, checking for NaN.

Uploaded by

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

Series Worksheet1 3

This document contains questions about pandas series attributes and methods. It asks about size, head, tail, reindex, CSV, dimensionality, creator of pandas, installing pandas, origin of name 'pandas', analyzing data in pandas, package vs library vs language, valid import statements, attributes of data frame, loc and iloc functions, adding rows, setting values to zero, shape of series, checking for NaN.

Uploaded by

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

KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION

CLASS XII – IP

NAME OF CHAPTER: Series

TOPIC: Series (Create Series, Access element, Filter value)

WORKSHEET NO. 1/3


QN. Questions M
1 Write a program to create a series to print scalar value “5” four times. 2
2 Write a program to create a series object F1 using a dictionary that stores 2
the number of furniture in each lab of your school.
Note: Assume four furniture names are Table, Sofa, Chair and stool
having 40, 2, 45, 26 items respectively and pandas library has been
imported as pd.
3 What will be the output of the following code: 1
import pandas as pd
L= [9,10,12]
S=pd.Series(L)
Dbl=pd.Series(data = S*2)
print(“New Series: “)
print(Dbl)
4 Write a program to create a series object using a dictionary that stores 2
the number of students in each house of CLASS 12D of your school.
Note: Assume four house names are Beas, Chenab, Ravi and Satluj
having 18, 2, 20, 18 students respectively and pandas library has been
imported as pd.
5 What will be the output of the following code: 1
>>>import pandas as pd
>>>A=pd.Series(data=[35,45,55,40])
>>>print(A==data)
What will be the output:
a. True b. False c. [35,45,55,40] d. Error
6 Find the output of following program. import numpy as np 1
d=np.array([10,20,30,40,50,60,70])
print(d [-4:])
7 What will be the output of the following code: 1
>>>import pandas as pd
>>>A=pd.Series(data=[35,45,55,40])
>>>print (A[A>45])
8 Write the output of the given command: import pandas as pd 1
s=pd.Series([1,2,3,4,5,6],index=['A','B','C','D','E','F'])
print(s[s%2==0])
9 What will be the output of the following code: 1
>>>import pandas as pd
>>>A=pd.Series(data=[35,45,55,40])
>>>print ([A>45])

6|Page
10 What will be the output of the following code: 1
>>>import pandas as pd
>>>A=pd.Series(data=[35,45,55,40])
>>>A[2:5]=25
>>>print (A)
11 Write a program to create a series object comp using a list that stores 2
the number of quantity of computer item in lab of your school.
Note: Assume four computer item names as index are KB, Mouse,
computer and printer having values are 30, 25, 20, 2 items respectively
and pandas library has been imported as pd.
***

7|Page
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: Series
TOPIC: Series (Create Series, Access element, Filter value)

WORKSHEET NO. 1/3

QN. Answers M
1 import pandas as pd 2
S=pd.Series(5, index=[1,2,3,4,5])
2 import pandas as pd 2
F={‘Table’ :40, ‘Sofa’ :2, ‘Chair’ :45, ‘Stool’ :26}
F1=pd.Series(St)
3 1

4 import pandas as pd 2
St={‘Beas’ :18, ‘Chenab’ :20, ‘Ravi’ :20, ‘Satluj’ :18}
S1=pd.Series(St)
5 d. Error 1
6 [40 50 60 70] 1
7 2 55 1
dtype: int64
8 B 2 1
D 4
F 6
dtype: int64
9 0 False 1
1 False
2 True
3 False
dtype: bool
10 0 35 1
1 45
2 25
3 25
dtype: int64
11 >>> i=['KB', 'Mouse', 'computer’,'printer'] 2
>>> data=[30, 25, 20, 2]
>>> comp=pd.Series(data, index=i)
>>> print(comp)
***

8|Page
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: Series
TOPIC: Series Attribute and methods

WORKSHEET NO. 2/3

Q. Questions M
No
1 Which attribute is used to get total number of elements in a Series? 1
a. size b. itemsize
c. shape d. ndim
2 To display last five rows of a series object ‘S’, you may write: 1
a. S.Head()
b. S.Tail(5)
c. S.Head(5)
d. S.tail()
3 To display top five rows of a series object ‘S’, you may write: 1
a. S.head()
b. S.Tail(5)
c. S.Head(5)
d. S.tail()
4 _________________method in Pandas can be used to change the index 1
of rows and columns of a Series or DataFrame:
(i) rename() (ii) reindex() (iii) reframe() (iv) none of the above
5 CSV stands for ______________ 1
6 Pandas Series is: _____ 1
a. 2-Dimensional b. 3-Dimensional c. 1 Dimensional d. Multidimensional
7 Python pandas was developed by:___________ 1
a. Guido van Rossum b. Travis Oliphant
c. Wes McKinney d. Brendan Eich
8 The command to install the pandas is: 1
a. install pip pandas b. install pandas
c. pip pandas d. pip install pandas
9 The name “Pandas” is derived from the term: 1
a. Panel Data b. Panel Series
c. Python Document d. Panel Data Frame
10 We can analyse the data in pandas with 1
a. Series b. Data Frame
c. Both of the above d. None of the above
11 Pandas is a: __________ 1
a. Package b. Language
c. Library d. Software
12 Which of the following import statement is not correct? 1
a. import pandas as CLASS12 b. import pandas as 1pd
c. import pandas as pd1 d. import pandas as pd
13 Which of the following is not an attribute of pandas data frame? 1
a. length b. T
c. Size d. shape
14 import pandas as pd 1
9|Page
s=pd.Series([1,2,3,4,5], index=['akram','brijesh','charu','deepika','era'])
print(s['charu'])
a. 1 b. 2 c. 3 d. 4
15 Assuming the given series, named stud, which command will be used to 1
print 5 as output?
Amit 90
Ramesh 100
Mahesh 50
john 67
Abdul 89
Name: Student, dtype: int64
a. stud.index b. stud.length
c. stud.values d. stud.size
16 A social science teacher wants to use a pandas series to teach about Indian 1
historical monuments and its states. The series should have the monument
names as values and state names as indexes which are stored in the given
lists, as shown in the code. Choose the statement which will create the
series:
import pandas as pd
Monument=['Qutub Minar','Gateway of India','Red Fort','Taj Mahal']
State=['Delhi','Maharashtra','Delhi','Uttar Pradesh']
a. S=df.Series(Monument, index=State)
b. S=pd.Series(State, Monument)
c. S=pd.Series(Monument, index=State)
d. S=pd.series(Monument, index=State)
17 Difference between loc() and iloc().: 1
a. Both are Label indexed based functions.
b. Both are Integer position-based functions.
c. loc() is label-based function and iloc() integer position-based function.
d. loc() is integer position-based function and iloc() index position-based
function.
18 Method or function to add a new row in a Series is: 1
a. .locate() b. .loc()
c. join d. add()
19 Rasha wants to set all the values to zero in Series, choose the right 1
command to do so:
a. S1=0 b. S1[]=0
c. S1[:]=0 d. S1[:]==0
20 Write the output of the given program: import pandas as pd 1
S1=pd.Series([5,6,7,8,10],index=['v','w',' x','y','z'])
Output required (5,)
a. print(S1.shape()) b. print(S1.shape)
c. print(S1.values) d. print(S1.size())
21 To check if the Series object contains NaN values, attribute is display. 1
a. hasnan b. nbytes
c. ndim d. hasnans

***

10 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER :Series
TOPIC: Series Attribute and methods

WORKSHEET NO. 2/3

QN. Answers M
1 Size 1
2 s.tail() 1
3 s.head() 1
4 reindex() 1
5 Comma separated value 1
6 c. 1 Dimensional 1
7 c. Wes McKinney 1
8 d. pip install pandas 1
9 a. Panel Data 1
10 c. Both of the above 1
11 c. Library 1
12 b. import pandas as 1pd 1
13 a. length 1
14 c. 3 1
15 d. stud.size 1
16 d. S=pd.Series(Monument,index=State) 1
17 c. loc() is label based function and iloc() integer position based function. 1
18 b.loc() 1
19 S1[:]=0 1
20 b. print(S1.shape) 1
21 (d) hasnans

11 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: Series
TOPIC: Vector operation, slicing

WORKSHEET NO. 3/3

QN Questions M
.
1 Consider the following series named animal: 2

Write the output of the command: print(animal[::-3])

2 Write the output of the given program: import pandas as pd 2


S1=pd.Series([5,6,7,8,10], index=['v','w',' x','y','z'])
l=[2,6,1,4,6]
S2=pd.Series(l,index=['z','y','a','w','v'])
print(S1-S2)
3 Give the output: 2
import pandas as pd
name=[‘Raj’,’Ankur’,’Harsh’]
p=pd.Series(name,index=[2,5,6])
print(p)
p1=p.reindex([2,5])
print (p1)
4 Give the output: 2
list1=[“Dance’,’Music’,’violin’, ‘guitar’,’drums’]
list2=[100,200,300,400,500,600]
list3=list1[:2]
list4=list2[2:5]
print(list3)
print(list4)
5 Consider the following series named color: 1
Color
1 Red
2 Green
3 Orange
4 Yellow
5 Black

dtype: object
Write the command that generates the output as:
2 Green
4 Yellow
dtype: object
6 What will be the output of the given code? 2

12 | P a g e
import pandas as pd
s=pd.Series([3,6,9,12,14],index=['
a','b','c','d','e']) print(s[‘a’]+s[‘c’])
7 2

8 How many elements will be there in the series named “S1”? 1


>>> S1 = pd.Series(range(5,10))
>>> print(S1)
9 Consider the following series 4
CapCntry = pd.Series(['NewDelhi', 'WashingtonDC', 'London', 'Paris', ’Tokyo’,
‘Beijing’], index=['India', 'USA', 'UK', 'France', ‘Japan’, ‘China’])
Write the output of the following statements:
i) CapCntry[: : 2] ii) CapCntry[5:1:-1]
iii) CapCntry[: :-1] iv) CapCntry[3:]
10 Consider the following code. Write appropriate words to complete 3
Line1: import pandas as pd
Line2: import___________ # Library name
Line3: A=np.______(2,11,2) # function name to get numpy array
Line 4: S=pd.Series(______, Index=[________________]) # Data name and
indexes
Line 5: Print(S)

TOTAL
***

13 | P a g e
KENDRIYA VIDYALAYA SANGATHAN, AHEMDABAD REGION
CLASS XII – IP
NAME OF CHAPTER: Series
TOPIC: Vector operation, slicing

WORKSHEET NO. 3/3

Q. Answers M
No.
1 W Wolf 2
B Bear
dtype: object
2 x NaN 2
a NaN
v -1.0
w 2.0
y 2.0
z 8.0
dtype: float64
3 2 Raj 2
5 Ankur
6 Harsh
dtype: object
2 Raj
5 Ankur
dtype: object

4 0 Dance 2
1 Music
2 300
3 400
4 500
5 Color[2:5:2] 2
6 12 2
7 2

8 5
14 | P a g e
s1
0 5
1 6
2 7
3 8
4 9
9 i)India NewDelhi 4
UK London
Japan Tokyo
dtype: object
ii) CapCntry[5:1:-1]
China Beijing
Japan Tokyo
France Paris
UK London
dtype: object
iii) CapCntry[: :-1]
China Beijing
Japan Tokyo
France Paris
UK London
USA WashingtonDC
India NewDelhi
dtype: object
iv) CapCntry[3:]
France Paris
Japan Tokyo
China Beijing
dtype: object
10 Line1: import pandas as pd 1
Line2: import_numpy as np # Library name
Line3: A=np.array(2,11,2) # function name to get numpy
array
Line 4: S=pd.Series(_A_____, Index=[_0,1,2]) # Data name and
indexes
Line 5: Print(S)

TOTAL

15 | P a g e

You might also like