CHAPTER 1 – PYTHON PANDAS - I
1. Pandas mainly used for
Data Recovery
Data Backup
Data Visualizations
Data Analysis
2. The Pandas word has derived from
Panel Data System
Panel Data Structure
Python Data Structure
Python Data System
3. Pandas has become a popular choice for data analysis because
It has tools for big data evaluations
It has tools to discover useful information
It provides support for decision making
All of these
4. Who is the main author of Pandas?
Guido Van Rossum
Wes McKinney
Dan Bader
Zed Shaw
5. Which of the following is not Pandas data structure?
Series
Data Frame
Queue
Panel
6. Which of the following statement is not correct for Pandas?
Pandas is open source built in library
Pandas offers high-performance, easy to use data structures
Pandas provides tools for backup and recovery
Pandas provides tools for data analysis
7. Which of the following is one of the feature of data structure?
Specialized way of storing data
Specialized way to read or write data
Reshape data into different forms
Support data visualizations
8. Which of the following term or word is not associated with pandas?
Index
Data
NaN
Record
9. Pandas series is a combination of
Records arranged in row and column
Collection of 1 dimensional data and associated index
Collection of 2 dimensional data
Collection of 3 dimensional data
10. Which of the following correct statement for creating empty series? (Assume
that pandas library is already imported as pd)
ser = pd.Series(NaN)
ser = pd.Series(None)
ser = pd.Series()
ser = pd.Series
11. The empty series object has which of the data type?
int64 float32
int32 float64
12. You can create a Python pandas series using?
sequence tuple
ndarray all of the above
13. While importing pandas and numpy, you must use identifier name as pd and
np only. Choose the correct answer
No, its not necessary
Yes, Always otherwise it will produce error
pd and np are keywords used for pandas and numpy
pd and np are ideintifiers used in the respecive module
14. Which one of the following is correct statement to create series 35,38,41,44
using a python sequence?
s = pd.Series(range(35,44,3))
s = pd.Series(range(35,45,3))
s = pd.Series(range(35 to 45,3))
s = pd.Series(range(35-45,3))
15. Which of the following is correct statement to create a series of multiple table
of 3?
s = pd.Series(range(3,31,3))
s = pd.Series(range(3,3*11))
s = pd.Series(range(3,3,3))
All of these
16. Which of the following is correct statement to create a series of multiple
repeated values 44,55 for three times?
s = pd.Series([44,55],3)
s = pd.Series(np.tile[44,55],3)
s = pd.Series(44,55,3)
s = pd.Series(range(44 and 55, 3))
17. Which of the following statement is correct to create a series of 5 elements
between 55 to 95?
s = pd.Series([55,95,5])
s = pd.Series(range(55,95,5))
s = pd.Series(np.linspace(55,95,5))
s = pd.Series((55,95,5))
18. While creating a series in which of the following way you must need to
specifies the index?
Using a sequence Using tuple
Using dictionary With a scalar value
19. Which of the following is correct statement for creating a series to assign
None to all series elements of 5 elements?
s = pd.Series()
s = pd.Series(None,index=[1,2,3,4,5])
s = pd.Series(none,5)
s = pd.Series(none*5)
20. Which of the following condition raise a ValueError while creating a series?
Values are provides without indexes
Indexes are not similar to number of values
Values are not similar to number of indexes
All of the above
21. Which of the following are ways to access series elements?
Using for loop Slicing
Indexing All of these
22. Pandas supports which of the following types of indexes?
Positional and Labelled Indexing
Numbered and Valued Indexing
Row and Column Indexing
Loop Indexing
23. The by default indexing is
Positional Index Labelled Index
Valued Index Sliced Index
24. ________ index will take user defined label as index.
Positional Index Labelled Index
Valued Index Sliced Index
25. Mr. Anuj is trying to access 3rd element from series named s using positional
index. Suggest him the correct statements from given statements:
s(2) s[2]
s{2} s[II]
26. Which of the following is correct way of assigning a labelled index to series?
s=pd.Series(index=range(5,10),[22,33,44,56,78])
s=pd.Series(index=range(5,10),dt=[22,33,44,56,78])
s=pd.Series({22,33,44,56,78},index=range(5,10))
s=pd.Series([22,33,44,56,78],index=range(5,10))
27. Which of the following is the correct statement to access index 3rd and 5th
values using positional index for series s?
s[3,5] s[(3,5)]
s[[3,5]] s([3,5])
28. Which of the following statement is false with respect to accessing series
elements through slicing?
It can be used as same as numpy or list slicing
It requires slicing start and end parameters
The values of last positional index is included
The series must be created with a sequence to access using slicing
29. Select the correct option to get the index preview in reverse order
s[-1::1] s[::-1]
s[-1:1:1] s[::]
30. What will be the output of following code:
import pandas as pd
s=pd.Series([11,12,13,14,15,16])
s[1:4] = 20
s=list(s)
print(l)
Select the correct output:
[11, 20, 20, 20, 15, 16]
[20, 20, 20, 20, 15, 16]
[20, 12, 13, 20, 15, 16]
[11, 20, 13, 20, 15, 16]
31. Series attributes are also known as series ____________
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) Only Statement 1 is Correct
b) Only Statement 2 is Correct
c) Both statements are correct
d) None of these statments are correct
43. What will be the output of following code?
import pandas as pd
s=pd.Series([10,20,30,40,50],index={'a','b'','c','d','e'})
s['d']
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) both are used for to access values based on index labels
b) iloc does not include the last element of the range
c) loc does not include the last element of the series
d) All of the above are correct
48. What will be the output for the following code:
import pandas as pd
s=pd.Series([66,22,11,44,55])
for i in range(s.size):
if s[i]>20:
print(s[i],end=",")
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
52. What will 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 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
55. Consider the following series object Named ‘Ser’:
0 578
1 235
2 560
3 897
4 118
What will be the output of following statements?:
i) print(ser.index) –> RangeIndex(start=0, stop=5, step=1)
ii) print(ser.values) –> [578 235 560 897 118]
iii) print(ser.shape) –> (5,)
iv) print(ser.size) –> 5
v) print(ser[3]) –> 897
vi) ser[2]= 999
ser[4]=ser[3]+4
print(ser[2],ser[4]) –> 999 901
vii) import pandas as pd
ser=pd.Series([578, 235, 560, 897, 118])
print(ser[2:])
print(ser[0:3])
print(ser[: :-1])
Ans:
2 560
3 897
4 118
dtype: int64
0 578
1 235
2 560
dtype: int64
4 118
3 897
2 560
1 235
0 578
dtype: int64
56. fruits = [‘Apple’,’Mango’, ‘Banana’, ‘Grapes’]
r2019 = pd.Series([100,80,30,60], index = fruits)
r2020 = pd.Series([150,100,50,80], index = fruits)
print (“Difference:”)
print (r2020 – r2019)
r2020 = r2019 + 100
print (r2020)
Ans:
Difference:
Apple 50
Mango 20
Banana 20
Grapes 20
dtype: int64
Apple 200
Mango 180
Banana 130
Grapes 160
dtype: int64
57. ser = pd.Series([5987,5634,3450,2500,1500,7899,6432,8756,9123,4400])
print(ser>5000)
print(ser==1500 or ser==1500)
print(ser[ser<5000])
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
Error Questions (Assume that all required packages are
imported)
1. ser = pd.series(range(4))
print(ser)
Ans.: In the statement pd.series, s of series should be capitalized.
2. ser = pd.Series(11,22,33,55, index = range(3))
Ans.: The values (11,22,33,55) in series should be passed in a list form.
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.
60. What are pandas? Explain in detail.
Pandas word derived from PANel Data System.
It becomes popular for data analysis.
It provides highly optimized performance with back end source code is purely
written in C or Python.
It makes a simple and easy process for data analysis.
61. List out common data structures supported by Pandas.
Series
Dataframe
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
63. What is a panda series? Explain with a suitable example.
Series is one dimensional data structure.
It contain an array of data.
Series contains two main components: An Index, An indexed associated with
array
64. How to create an empty series? Explain with a suitable example.
To create an empty series use Series() method with Pandas object.
Observe this code:
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))