Python Pandas MCQ Questions And Answers
This section focuses on "Python Pandas" for Data Science. These Python Pandas Multiple Choice Questions (MCQ) should be practiced to improve the Data Science skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. Pandas is an open-source _______ Library?
A. Ruby
B. Javascript
C. Java
D. Python
View Answer
Ans : D
Explanation: Pandas is an open-source Python Library providing high-performance data manipulation and analysis tool using its powerful data structures.
2. Python pandas was developed by?
A. Guido van Rossum
B. Travis Oliphant
C. Wes McKinney
D. Brendan Eich
View Answer
Ans : C
Explanation: Pandas is a high-level data manipulation tool developed by Wes McKinney.
3. Pandas key data structure is called?
A. Keyframe
B. DataFrame
C. Statistics
D. Econometrics
View Answer
Ans : B
Explanation: Pandas is built on the Numpy package and its key data structure is called the DataFrame.
4. 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
View Answer
Ans : A
Explanation: Retrieve a single element using index label value.
5. In pandas, Index values must be?
A. unique
B. hashable
C. Both A and B
D. None of the above
View Answer
Ans : C
Explanation: Index values must be unique and hashable, same length as data. Default np.arrange(n) if no index is passed.
6. 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)
View Answer
Ans : C
Explanation: A pandas Series can be created using the following constructor : pandas.Series( data, index, dtype, copy)
7. Which of the following is correct Features of DataFrame?
A. Potentially columns are of different types
B. Can Perform Arithmetic operations on rows and columns
C. Labeled axes (rows and columns)
D. All of the above
View Answer
Ans : D
Explanation: All the above are feature of dataframe.
8. What will be syntax for pandas dataframe?
A. pandas.DataFrame( data, index, dtype, copy)
B. pandas.DataFrame( data, index, rows, dtype, copy)
C. pandas_DataFrame( data, index, columns, dtype, copy)
D. pandas.DataFrame( data, index, columns, dtype, copy)
View Answer
Ans : D
Explanation: A pandas DataFrame can be created using the following constructor : pandas.DataFrame( data, index, columns, dtype, copy)
9. A panel is a ___ container of data
A. 1D
B. 2D
C. 3D
D. Infinite
View Answer
Ans : C
Explanation: A panel is a 3D container of data. The term Panel data is derived from econometrics and is partially responsible for the name pandas : pan(el)-da(ta)-s.
10. Axis 1, in panel represent?
A. minor_axis
B. major_axis
C. items
D. None of the above
View Answer
Ans : B
Explanation: major_axis : axis 1, it is the index (rows) of each of the DataFrames.
11. 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
View Answer
Ans : C
Explanation: Both option A and B are true.
12. Which of the following thing can be data in Pandas?
A. a python dict
B. an ndarray
C. a scalar value
D. All of the above
View Answer
Ans : D
Explanation: The passed index is a list of axis labels.
13. Which of the following takes a dict of dicts or a dict of array-like sequences and returns a DataFrame?
A. DataFrame.from_items
B. DataFrame.from_records
C. DataFrame.from_dict
D. All of the above
View Answer
Ans : A
Explanation: DataFrame.from_dict operates like the DataFrame constructor except for the orient parameter which is 'columns' by default.
14. The ________ project builds on top of pandas and matplotlib to provide easy plotting of data.
A. yhat
B. Seaborn
C. Vincent
D. Pychart
View Answer
Ans : B
Explanation: Seaborn has great support for pandas data objects.
15. Which of the following makes use of pandas and returns data in a series or dataFrame?
A. pandaSDMX
B. freedapi
C. OutPy
D. Inpy
View Answer
Ans : B
Explanation: freedapi module requires a FRED API key that you can obtain for free on the FRED website.
16. 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
View Answer
Ans : C
Explanation: ndim : Returns the number of dimensions of the underlying data, by definition 1
17. What will be output for the following code?
import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(4))
print s.ndim
A. 0
B. 1
C. 2
D. 3
View Answer
Ans : B
Explanation: Returns the number of dimensions of the object. By definition, a Series is a 1D data structure, so it returns 1.
18. What will be output for the following code?
import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(2))
print s.size
A. 0
B. 1
C. 2
D. 3
View Answer
Ans : C
Explanation: size : Returns the size(length) of the series.
19. Which of the following indexing capabilities is used as a concise means of selecting data from a pandas object?
A. In
B. ix
C. ipy
D. iy
View Answer
Ans : B
Explanation: ix and reindex are 100% equivalent.
20. Which of the following is false?
A. The integer format tracks only the locations and sizes of blocks of data.
B. Pandas follow the NumPy convention of raising an error when you try to convert something to a bool.
C. Two kinds of SparseIndex are implemented
D. The integer format keeps an arrays of all of the locations where the data are not equal to the fill value
View Answer
Ans : A
Explanation: The block format tracks only the locations and sizes of blocks of data.
Discussion