Chapter 1 - Python Pandas - I
Chapter 1 - Python Pandas - I
Methods
Events
Properties
Characteristics
32. Select the correct statement to assign a new name MySeries to a series object
named s
s.Name(‘MySeries’)
s.name=’MySeries’
s(‘MySeries’)
s.Name=’MySeries’
33. Mr. Asutosh has created a series with object s1 and assigned a name the index
as ‘states’. Which of the following statement should he use to print the index of
series by assigned name?
s1.Index.Name
s1.index.name
s1.Name
s1.index
34. Which of the following attribute gives the following output – (4,) for
following data frame?
0 23
1 25
2 28
4 30
s.shape()
s.index
s.shape
s.size
35. Ms. Anita wants to print only list of values from the series. She should use
which of the following attribute?
s.value
s.values
s.val
s.eval
36. Which of the following attribute is used to returns the total number of rows?
countAll
size
shape
ndim
37. Ms. Hetvee wants to check whether series is empty or not. But she is confused
to how to do the same, help her to select the correct method out of the
following?
s.empty()
s.empty
s.isempty
s.None
38. Which of the following attribute is used check whether a series contains NaN
value or not?
s.NaN
s.None
s.hasnans
s.nan
39. Which of the following function of series is used to return first ‘n’ elements
from series?
s.head()
s.tail()
s.top()
s.on()
40. The head function returns how many elements by default from the series?
2
3
4
5
41. Ms. Priya is a python developer and she created a series using the following
code, but she missed some of the lines given as blank. Fill that blanks and help
her to complete the code:
import pandas as pd
import ________ as np
s1=pd.Series([3,4,_____,44,67])
print(s1)
Output:
0 3
1 4
2 NaN
3 44
4 67
a) numPy, no.None
b) numpy,np.nan
c) numpy,np.NaN
d)NumPy,np.NaN
42. Mr. Sidhhart wants to define the index explicitely for a series named s. Which
of the following statement(s) is/are correct?
Statement 1: s.index=[‘1st’,’2nd’,’3rd’,’4th’]
Statement 2: s.index(‘1st’,’2nd’,’3rd’,’4th’)
a) d
b) 30
c) 40
d) 4
44. Mrs. Payal Mishra wanted to access multiple index value from series s. Which
of the following statement is correct for her?
a) s.index=[0,1,2,3,4]
b) s.index(0,1,2,3,4)
c) s[0,1,2,3,4]
d) s[[0,1,2,3,4]]
45. Observe the code and choose the correct output:
import pandas as pd
s=pd.Series(11,22,33,44,55)
print(s[-3:])
a)
4 33
3 44
2 55
dtype: int64
b)
2 33
3 44
4 55
dtype: int64
c)
0 11
1 22
2 33
dtype: int64
d)
3 44
4 55
dtype: int64
46. Which of the following code is helpful to access first 3 index values?
a) s[:3]
b) s[::3]
c) s[3:]
d) s[:3:]
47. Which of the following statement is correct with respect to loc and iloc?
a) 66,22,44,55
b) 22,44,55,66
c) 66,22,44,66
d) Error
49. Ms. Advika wants to apply name for the index in series named sal for month
wise salary of her employees. Choose the correct statment for her:
a) s.index=’Month’
b) s.index.name=’Month’
c) s.index(‘Month’)
d) s.index.name[‘Month’]
50. Tushar is new learner for python pandas series. He learned some of the
concepts of python in class 11 with numpy module. He wants to create a series
of values multiply by 7 between 20 to 30 with following code. The index should
between 20 to 30 and evey value should be multiply with 7. Help him to create
series by folloiwng code:
import pandas as pd
import numpy as np
s=np.arange(20,30)
a) sm7= pd.Series(s,s*7)
b) sm7=pd.Series(s*7,s)
c) sm7=pd.Series([s*7],index=s)
d) All of these
51. What will be the output of the following code:
import pandas as pd
s1=pd.Series([4,5,7,8,9],index=['a','b','c','d','e'])
s2=pd.Series([1,3,6,4,2],index=['a','p','c','d','e'])
print(s1-s2)
a)
a 3.0
b0
c 1.0
d 4.0
e 7.0
p0
dtype: float64
b)
a 3.0
b NaN
c 1.0
d 4.0
e 7.0
p NaN
dtype: float64
c)
a 3.0
c 1.0
d 4.0
e 7.0
dtype: float64
d)
a 3.0
b–
c 1.0
d 4.0
e 7.0
p–
dtype: float64
import pandas as pd
s1=pd.Series([4,5,7,8,9],index=['a','b','c','d','e'])
s2=pd.Series([1,3,6,4,2],index=['a','p','c','d','e'])
print(s1==s2)
a)
a True
b False
c True
d False
e True
dtype: bool
b)
a False
b False
c False
d False
e False
dtype: bool
c)
a True
b True
c True
d True
e True
dtype: bool
d)
a False
b True
c False
d False
e True
dtype: bool
53. Which of the following is not a correct statement to delete the element stored at
3rd position?
a) del s[3]
b) s.pop(3)
c) s.drop(3)
d) s.delete(3)
54. Mr. Tript is working IT company. His boss assigns him some work to be done
with series on which he need to do some tasks and perform some operations. The
code is as folloiwng suggest the him the best options for his work:
import pandas as pd
s1=pd.Series([97,94,95,88,87,77],index=['Radhika','Maitree','R
itika','Rajul’ ,’Shivani','Mridul'])
Based on given code, answer the following questions:
1. He wants to print Name and Values for Ritika and Mridul, which of the
following command is correct:
s1.loc[‘Ritika’,’Mridul’]
s1.loc[‘Ritika’:’Mridul’:3]
s1.loc[‘Ritika’:’Mridul’]
s1.loc[‘Ritika’-‘Mridul’]
2. Help to reset all values with 0 which ends with 7. Which of the following code is
correct:
s1[s1/10==7]=0
s1[s1%10==7]=0
s1[s1//10==7]=0
s1[s1**7]=0
3. What will be output of: print(s1.shape)
(6,)
6
[6]
{6}
4. He wants to check the availability of NaN values in index. Which of the
following is correct statement for him?
s1.none
s1.nan
s1.hasnans
s1.hasNan
5. He wants to return total number elements from the series. Which of these
statement is correct?
s1.index
s1.length
s1.itemsize
s1.size
6. He wants to check whether series is empty or not?
s1.empty
s1.none
s1.blank
s1.zero
0 578
1 235
2 560
3 897
4 118
Ans.
0 True
1 True
2 False
3 False
4 False
5 True
6 True
7 True
8 True
9 False
dtype: bool
58. l=[]
for i in range(1,11,2):
l.append(i)
ser=pd.Series(l)
print(ser)
ser1=pd.Series(l*3)
print(ser1)
Ans.:
0 1
1 3
2 5
3 7
4 9
dtype: int64
0 1
1 3
2 5
3 7
4 9
5 1
6 3
7 5
8 7
9 9
10 1
11 3
12 5
13 7
14 9
dtype: int64
59. ser = pd.Series(range(1,10))
ser.head(4)
ser.tail()
ser.head()
Ans.:
0 1
1 2
2 3
3 4
dtype: int64
4 5
5 6
6 7
7 8
8 9
dtype: int64
0 1
1 2
2 3
3 4
4 5
dtype: int64
print(ser)
3. l = np.array([‘C’,’C++’,’Java’,’Python’])
s = pd.Series(l,index=[501,502,503,504])
print(s[501,502,504])
Ans. Line no. 3, the index should be enclosed with more square brackets.
4. ser = pd.Series(range(1,12,2),index=list(‘pqrst’))
Ans. Indexes are not provided properly. The elements of series are 6, where indexes are
5.
62. How to use pandas library in a program? Illustrate the answer with an example.
To use pandas libary in the program user need to import the pandas package.
For example, import pandas as pd
import pandas as pd
ser = pd.Series()
65. How to create a series with an example: A python sequence, NumPy Array, A
dictionary, A scalar value
A python sequence
import pandas as pd
ser=pd.Series(range(5))
NumPy Array
import pandas as pd
import numpy as np
arr = np.arange(1,10,1)
ser = pd.Series(arr)
A scalar value
import pandas as pd
ser = pd.Series(5,range(1,5))