1.
Series is ……………….. data structure of Python Pandas.
(a) 1-Dimensional
(b) 2-Dimensional
(c) Multi Dimensional
(d) None of these
Ans : (a)
2.
Which of the following is true?
(a) If data is an ndarray, index must be the same
length as data
(b) Series is a one-dimensional labeled array capable
of holding any data type.
(c) Both A and B
(d) None of the above
Ans : (c)
Explanation: Both option A and B are
true.
3.
What will be output for the following
code?
import pandas as pd
s = pd.Series([1,2,3,4,5],index =
['a','b','c','d','e'])
print s['a']
(a) 1
(b) 2
(c) 3
(d) 4
Ans : (a)
Explanation: Retrieve a single
element using index label value.
4.
What will be correct syntax for
pandas series?
(a) pandas_Series( data, index, dtype, copy)
(b) pandas.Series( data, index, dtype)
(c) pandas.Series( data, index, dtype, copy)
(d) pandas_Series( data, index, dtype)
Ans : (c)
Explanation: A pandas Series can be
created using the following constructor : pandas.Series( data, index, dtype,
copy)
5.
Why ndim is used?
(a) Returns the number of elements in the underlying data.
(b) Returns the Series as ndarray.
(c) Returns the number of dimensions of the underlying data, by definition 1.
(d) Returns a list of the axis labels
Ans : (c)
Explanation: ndim : Returns the
number of dimensions of the underlying data, by definition 1
6.
What is the purpose of itemsize
attributes in Series.
(a) Return the type of data values stored in Series object.
(b) Returns the size in byte for each item
(c) Tells the type of the object passed to it.
(d) None of these
Ans B,
Explanation:
Returns the size in byte for each
item.
7.
What is the meaning of NaN
(a) Not any Number
(b) Not any Numeric
(c) Not available number
(d) None of these
Ans: A, missing or empty values(NaN).
8.
What is the purpose of the following
code:
>>>obj1=pd.Series()
>>>obj1.empty
(a) Not any number
(b) Empty series
(c) Both (a) and
(b)
(d) Delete series
Ans. b, to check series empty or not.
9.
Which is not series attribute:
(a) index
(b) dtype
(c) shape
(d) all of these
Ans : (d)
10. What will return Series.hasnAns :
(a) It returns a tuple of shape of the data.
(b) It returns the size of the data.
(c) It returns True if there are any NaN values, otherwise returns false.
(d) It returns the number of bytes in the data.
Ans: (c)
11.
When a Series created, are the data
values mutable or immutable.
(a)
Yes, data can be modified and are
mutable.
(b)
No, data can be modified and are
mutable.
(c) Yes, data can not be modified and are immutable.
(d)
No, data can not be modified and are
immutable.
Ans: (c)
12.
Consider the following snippet:
import pandas as pd
import numpy as np
ser=pd.Series(np.arange(10,20,1))
print(ser.head())
(a) 0
11
1 12
2 13
3 14
4 15
dtype: int32
(b) 0
10
1 11
2 12
3 13
4 14
dtype: int32
(c) 1 11
2
12
3
13
4
14
5 15
dtype: int32
(d)
Both (a) and (c)
Ans: (b)
13.
What is the output of the following
snippet:
import pandas as pd
import numpy as np
ser=pd.Series([10,20,np.nan,40,50])
print(ser.count())
(a)
5
(b)
4
(c) 3
(d)
6
Ans : (b), It is not 5 count method returns the number
of non-NaN values is series.
14.
What is the output of the following
snippet:
import pandas as pd1
import numpy as np1
data={'P':0,'R':1,'E':2,'M':2}
s=pd1.Series(data,index=['P','c','M','a'])
print(s)
(a) P 0.0
c NaN
M 2.0
a NaN
dtype: float64
(b) P 0.0
c 1.0
M 2.0
a NaN
dtype: float64
(c) P 0.0
c 1.0
M 2.0
a 2.0
dtype: float64
(d) P NaN
c 0.0
M 2.0
a NaN
dtype: float64
Ans: (a)
15.
What in output of the following code
:
import pandas as pd
seriesCapCntry=pd.Series(['NewDelhi','WashingtonDC','London','Paris'],\
index=['India','USA','UK','France'])
print(seriesCapCntry['USA':'France'])
(a)USA WashingtonDC
France Paris
dtype: object
(b)UK London
France Paris
dtype: object
(c) USA
WashingtonDC
UK London
France Paris
dtype: object
(d)
None of these
Ans: (c)
16.
What in output of the following code
:
import
pandas as pd
seriesCapCntry=pd.Series(['NewDelhi','WashingtonDC','London','Paris'],\
index=['India','USA','UK','France'])
print(seriesCapCntry[1:3])
(a)
USA
WashingtonDC
UK London
dtype: object
(b)
UK London
France Paris
dtype: object
(c) USA
WashingtonDC
UK London
France Paris
dtype: object
(d)
None of these
Ans: (a), it excludes the value at index position 3.
17.
Given a Pandas series called s1, the
command which will display the las 3 rows is___________
(a)
print(s1.tail(3))
(b)
print(s1.Tail(3))
(c) print(s1.tails(3))
(d)
print(s1.Tails(3))
Ans: (a)
18.
What is the output of the following snippet?
import
pandas as pd
s1=pd.Series(‘Hello’,[1,2,3,4])
print(s1)
(a)
1 Hello
2 Hello
3 Hello
4 Hello
dtype: Object
(b)
0
Hello
1
1
2
2
3 3
4
4
(c) 1 Hello
2
1
3
2
4 3
5
4
(d)
None of these
Ans : (a)
19.
What is the output of the following snippet?
import
pandas as pd
import
numpy as np
s1=pd.Series([10,11,20,np.NaN,44,60])
print(s1[:2])
(a)
1 11
2
20
(b)
0 10
1
11
(c) 0 11
1
20
(d)
2 20
2
NaN
Ans : (b)
20.
What is the output of the following snippet?
import
pandas as pd
import
numpy as np
s1=pd.Series([10,11,20,np.NaN,44,60])
print(s1[::2])
(a)
0
10.0
2
20.0
3
44.0
(b)
0
20.0
2
44.0
4
Nan
(c) Both (a) and (b)
(d)
None of these
Ans : (a)
21.
What is the output of the following snippet?
import pandas as pd
import numpy as np
s1=pd.Series([10,11,20,np.NaN,44,60])
print(s1[::-2])
(a)
5
60.0
3
NaN
1
11.0
dtype: float64
(b)
5
20.0
3
NaN
1
11.0
dtype: float64
(c) 5 440.0
3
NaN
1
11.0
dtype: float64
(d)
All of these
Ans : (a)
22.
Which source code is correct for
following output?
a 6700
b 5600
c 5000
d 5200
dtype:
int64
(a)
import pandas as pd
idx=['a','b','c','d']
s2=pd.Series([6700,5600,5000,5200])
print(s2)
(b)
import pandas as pd
idx=['a','b','c','d']
s2=pd.Series([6700,5600,5000,5200]
index=idx)
print(s2)
(c) import pandas as pd
s2=pd.Series([6700,5600,5000,5200])
print(s2)
(d)
import pandas as pd
idx=['a','b','c','d']
s2=pd.Series([6700,5600,5000,5200],
index=idx)
print(s2)
Ans: (d)
23.
What is the output of the following snippet?
import pandas as pd
info=pd.Series(data=[111,222,333])
print(info>112)
(a)
0
True
1
True
2
True
dtype: bool
(b)
0
False
1
True
2
False
dtype: bool
(c) 0 False
1
True
2
True
dtype: bool
(d)
0
False
1
True
2
True
dtype: bool
Ans: (d)
24.
Which source code is correct for
following output?
1 222
2 333
dtype:
int64
(a)
import pandas as pd
info=pd.Series(data=[111,222,333])
print(info[info>112])
(b)
import pandas as pd
info=pd.Series(data=[111,222,333])
print(info[info>=112])
(c) import pandas as pd
info=pd.Series(data=[111,222,333])
print(info[info==112])
(d)
Both (a) and (b)
Ans (d)
25.
Fill in the blanks:
import
pandas as ________
s2=pds.Series([6700,5600,4000,5200],
index=['a','b','c','d'])
print(s2.sort_values(___________))
(a)
pd, ascending=True
(b)
Pds, ascending=False
(c) pds, ascending=True
(d)
None of these
Ans: (d)
No comments:
Post a Comment