0% found this document useful (0 votes)
255 views9 pages

MCQ Based On Series

The document discusses pandas Series data structure. Key points include: - Series is a 1-D labeled array that consists of both index and data elements. - Series can be created from Python sequences, dictionaries, scalar values, and NumPy arrays. - We can access and manipulate individual elements or slices of a Series using various indexing methods like .loc, .iloc, and standard Python slicing.

Uploaded by

subbu
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)
255 views9 pages

MCQ Based On Series

The document discusses pandas Series data structure. Key points include: - Series is a 1-D labeled array that consists of both index and data elements. - Series can be created from Python sequences, dictionaries, scalar values, and NumPy arrays. - We can access and manipulate individual elements or slices of a Series using various indexing methods like .loc, .iloc, and standard Python slicing.

Uploaded by

subbu
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/ 9

Introduction to Python Libraries Data Structure in Pandas:

Series, attributes, functions, indexing and slicing


1. Fill in the blanks :

a. row
b. index
c. row_index
d. Any above option

2. While trying to create series from dictionary, keys of dictionary become index.
a. True
b. False
c. Depends on Python Version
d. Depends on Machine Configuration

3. Predict data elements of series1 :

a. 5,1,1,1
b. 5,0,0,0
c. 5,1,5,1
d. 5,5,5,5

4. Which index, data elements will be printed by below code as output :

a. Data : 12,13,14 along with series-index 1,2,3


b. Data : 13,14 along with series-index 'C','D'
c. Data : 13,14 along with series-index 2,3
d. Data : 12,13,14 along with series-index 'B','C','D'

4
5. To have output of below python code as shown in figure, identify which attribute can be used to fill in
the blank.

a. loc
b. iloc
c. loc or iloc
d. Neither loc nor loc

6. What will be the output of following code-


import pandas as pd
s1=pd.Series([1, 2, 2, 7, ’Sachin’, 77.5])
print(s1.head())
a. Last data elements of series along with its indices i.e. -1.
b. First data element of series along with its indices i.e. 0.
c. Entire series
d. First five data elements of series along with its indices i.e. 0,1,2,3,4 respectively

7. Series is 1-D labelled array having two parts i.e. Index, Data. We can create series from:
a. Python Sequence , Dictionary
b. All 4 ( ie Python Sequence , Dictionary , Scalar value , Numpy Array)
c. Scalar value , Numpy Array
d. None of stated option.

8. To access elements as 12,13,14 respectively , what python command can be used

a. s1.iloc[1:3] or s1.loc[ 'b': 'd' ]


b. s1.loc[1:3]
c. s1.iloc[ 'b': 'd' ]
d. Neither s1.iloc[1:3] nor s1.loc[ 'b': 'd' ]

9. To create an empty Series object , we can use:


a. pd.Series(empty)
b. pd.Series(numpy.NaN)
c. pd.Series()
d. Any of above mentioned options

5
10. To get the number of dimensions of Series object, _______ attribute is used.
a. size
b. shape
c. itemsize
d. ndim

11. To skip not numeric or null values in series, we can use _________ attribute.
a. skip
b. skipna
c. skipNaN
d. Not possible

12. To get last element of series s1, we may use s1._________ function.
a. tail(1)
b. tail()
c. last[1]
d. last[-1]

13. Identify false statement regarding series data structure of pandas library :
a. Series is homogenous data structure.
b. Series is a two dimensional data structure.
c. Size of series is mutable.
d. Both (b) & (c)

14. Rohan wants to create a series from a list, having index as ‘A’ , ‘B’,’C’ respectively. However,
below code is generating error. Identify which lines are responsible for generating error.
Line 1: import pandas as p1
Line 2: l1=[ 1, 2 , 3]
Line 3: l2= list(‘ABC’)
Line 4: S1= p1. series( l1 , rows=l2)
a. Line 4
b. Line 3
c. Line 2
d. Line 1

15. Identify out of below options, which could correct above code in order to help Rohit.
a. In Line-4, Use p1.Series instead of p1.series.
b. In Line-4, Use ‘index’ attribute instead of rows attribute.
c. Both (a) & (b)
d. In Line-1, use import pandas only.

16. Aman , Riya and Neha are involved in a group discussion. All 3 students are representing below
statements :
Aman : Series is a one dimensional data structure.
Riya : Series can have only default index ie 0,1,2. Thus, these index can’t be customised.
Neha : Size of series is immutable . Thus, it can’t be changed once declare.
Identify which student(s) is/are representing wrong fact(s).

6
a. Aman
b. Both Aman and Riya
c. Neha
d. Riya

17. Choose correct option :


D1={ ’A’:’CS’, ‘B’:’IP’}
D2={ ’B’:’IP’, ‘A’:’CS’}
Statement 1: Output of print (D1==D2) is True.
Statement 2: Dictionary is a collection of key-value pairs. It is not a sequence.
a. Only Statement 1 is true.
b. Only Statement 2 is true.
c. Both Statement 1 and 2 are true, but Statement 2 is not correct reasoning of Statement 1.
d. Both Statement 1 and 2 are true, but Statement 2 is correct reasoning of Statement 1.

18. Choose correct option :


import pandas as p1
import numpy as np
a1=np.arange(2,11,2)
s1=p1.Series(a1,index=list(‘ABCDE’))
print(s1.ndim)
Statement 1: Above code will give output as 1.
Statement 2: Series is a one dimensional data structure.

a. Only Statement 1 is true.


b. Only Statement 2 is true.
c. Both Statement 1 and 2 are true, but Statement 2 is not correct reasoning of Statement 1.
d. Both Statement 1 and 2 are true, but Statement 2 is correct reasoning of Statement 1.

19. Choose correct option :


import pandas as p1
l1=[11,12,13,14]
s1=p1.Series(l1 , index=list(‘abc’))
Statement 1: No. of indexes should be equal to number of data elements in series.
Statement 2: Above code will execute fine.
a. Only Statement 1 is true.
b. Only Statement 2 is true.
c. Both Statement 1 and 2 are true, but Statement 2 is not correct reasoning of Statement 1.
d. Both Statement 1 and 2 are true, but Statement 2 is correct reasoning of Statement 1.

20. Choose correct option :


Reena created a series s1 having data elements as 12, 13, 14, 15 with index as I1, I2, I3,I4
respectively. She is using code either s1.loc [‘I2’:’I3’] or s1.iloc[1:3]
Statement 1: Both code will give identical output.
Statement 2: Both codes can be used to access data elements as 13,14,15 respectively.
a. Only Statement 1 is true.
b. Only Statement 2 is true.
c. Both Statement 1 and 2 are true, but Statement 2 is not correct reasoning of Statement 1.
d. Both Statement 1 and 2 are true, but Statement 2 is correct reasoning of Statement 1.

7
21. Choose correct option :
Assume there is a series s1 having data elements as 11, 12, and 13 respectively. Programmer ‘Alok’
wrote print(s1+2) in his python program.
Statement 1: A series will data elements as 13, 14, 15 will get printed.
Statement 2: Series supports vectorized operation.
a. Only Statement 1 is true.
b. Only Statement 2 is true.
c. Both Statement 1 and 2 are true, but Statement 2 is not correct reasoning of Statement 1.
d. Both Statement 1 and 2 are true, but Statement 2 is correct reasoning of Statement 1.

22 Predict output of s1>20 if series s1 is given below:


Index Elements
I 15
II 20
III 25
IV 30

Index Elements
I False
II False
III True
IV
a. True

Index Elements
III 25
IV 30
b.

Index Elements
II 20
III 25
IV 30
c.
d. None of the above

23. Assume series s1 is given below. Predict output of s1[s1%5==0 or s1>=20]


Index Elements
I 16
II 20
III 21
Index Elements
I False
II True
III False
a.

Index Elements
II 20
b.
8
Index Elements
II True
III True
c.
Index Elements
II 20
III 21
d.

24. Predict output :


import pandas as p1
s1=p1.Series( [11,12,13,14])
print(s1.index)
a. Syntax Error
b. [ 0,1,2,3]
c. [ ‘I’,’II’,’III’,’IV’]
d. [‘A’,’B’,’C’,’D’]
25. What will be correct syntax for pandas series?
a. pandas_Series( data, index, dtype)
b. panda.series( data, index, dtype)
c. pandas.Series( data, index, dtype)
d. panda_Series( data, index, dtype)
26. Which of the following are modules/libraries in Python?
a. NumPy
b. Pandas
c. Matplotlib
d. All of the above

27. Which of the following library in Python is used for plotting graphs and visualization.
a. Pandas
b. Numpy
c. Matplotlib
d. None of the above

28. Which of the following command is used to install pandas?\


a. pip install pandas
b. install pandas
c. pip pandas
d. None of the above

29. Identify incorrect syntax for importing pandas library :


a. import pandas as p1
s1=p1.Series( [11 , 12 , 13])
b. import pandas
s1=p1.Series( [11 , 12 , 13])
c. from pandas import Series
s1=Series( [11 , 12 , 13])
d. import pandas
s1=pandas.Series( [11 , 12 , 13])

9
30. Which of the following code will generate the following output?
Jan 31
Feb 28
Mar 31
dtype: int64

a. import pandas
S1 = pd.Series(data = [31,28,31], index=["Jan","Feb","Mar"])
print(S1)
b. import pandas as pd
S1 = p1.series([31,28,31], index=["Jan","Feb","Mar"])
print(S1)
c. import pandas as pd
S1 = pd.Series([31,28,31], columns=["Jan","Feb","Mar"])
print(S1)

d. import pandas as pd
S1 = pd.Series([31,28,31], index=["Jan","Feb","Mar"])
print(S1)
31 To create an empty Series Object , You can use:
a. pandas.Series(empty)
b. pandas.Series(np.Nan)
c. pandas.Series()
d. all of these
32 To get the number of dimensions of a Series object, ___________ attribute is displayed.
1. Index
2. Size
3. Itemsize
4. Ndim
33 To specify datatype int16 for a Series object, you can write:
a. pandas.Series(data=array,dtype=int16)
b. pandas.Series(data=array,dtype=numpy.int16)
c. pandas.Series(data=array.dtype=pandas.int16)
d. All of the above
34 To get the size of the datatype of the items in Series object, you can use ____________ attribute.
a. Index
b. Size
c. Itemsize
d. Ndim
35 To get the number of elements in a Series object, _____________ attribute may be used.
a. Index
b. Size
c. Itemsize
d. Ndim

10
36 To get the number of bytes of the Series data, _____________ attribute is displayed.
a. hasnans
b. nbytes
c. ndim
d. dtype
37 To display third element of a Series object S, you will write__________________.
a. S[:3]
b. S[:2]
c. S[3]
d. S[:2]
38 To display first three elements of a Series object S, you may write____________.
a. S[:3]
b. S[3]
c. S3rd]
d. All of these
39 To display last five rows of a Series object S, You may write_____________.
a. head()
b. head(5)
c. tail()
d. tail(5)
40 Missing data in pandas object is represented through:
a. Null
b. None
c. Missing
d. Nan
41 Given a pandas series called Sequences, the command which will display the first 4 rows is _______
a. print(Sequences.head(4))
b. print(Sequences.Head(4))
c. print(Sequences.heads(4))
d. print(Sequences.Heads(4))
42 To check if the Series object contains NaN values, ___________ attribute is displayed.
a. hasnans
b. nbytes
c. ndim
d. dtype
43 A __________________ is a pandas data structure that represents a 1-D array like object.
a. Array
b. Numpy
c. Series
d. Dataframe

11
44 You can use numpy._________________ for missing data.
a. NaN
b. Missing
c. None
d. NULL
45 To specify datatype for a Series object, __________________ argument is used.
a. Datatype
b. Type
c. dtype
d. Dtype
46 The _____________ function on Series object returns total elements in it including NaNs.
a. Total()
b. len()
c. length()
d. total()
47 The ________________ function on Series object returns only the count of non-NaN values in it.
a. count()
b. total()
c. length()
d. len()
48 Series is ________________mutable.
a. value size
49 Series is not ________ mutable.
a. Size b. value
50 Given are two objects, a list object namely lst1 and a series object namely ser1, both are having
similar values i.e. 2,4,6,8. Find out the output produced by following statements:
print(lst1*2)
print(ser1*2)
a. [2,4,6,8,2,4,6,8]
1. 4
2. 8
3. 12
4. 16
b. [4,8,12,16]
1 2
2 4
3 6
4 8
5 2
6 4
7 6
8 8

12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy