Pandas Review Questions

Table of Contents

Preface

This page contains review questions for teaching ITSE-1372 Int Comp Program Python at Austin Community College in Austin, TX.

The questions and the answers on this page are connected by hyperlinks to make it easy for you to navigate from the question to the answer and back again.

The questions on this page are similar to the questions that you will find on the proctored tests for this course. Therefore, it is strongly recommended that you study the material until you thoroughly understand the material covered by these questions.

Questions

Question 1.

True or False: Pandas is a software library written for the Python programming language.

Answer 1

Question 2

True or False: The Pandas library provides special scientific functions for the manipulation of numerical tables and time series.

Answer 2

Question 3

True or False: Pandas provides three important data structures: Series, DataFrame, and BinaryTree.

Answer 3

Question 4

True or False: A Series is a one-dimensional labeled array-like object. It is capable of holding any data type, e.g. integers, floats, strings, Python objects, and so on. It can be seen as a data structure with two arrays: one functioning as the index, i.e. the labels, and the other one contains the actual data.

Answer 4

Question 5

True or False: Like the keys in a dictionary, the index values for a Series are required to be unique.

Answer 5

Question 6

True or False: The default index for a Series is a numeric zero-based index.

Answer 6

Question 7

True or False: If the default numeric index for a Series doesn't suit your needs, you can replace it with a set of Index values of your choosing, by providing a second argument to the Series constructor.

Answer 7

Question 8

True or False: A Series object has its own built-in plot method.

Answer 8

Question 9

True or False: The plot method for a Series object can create the following kinds of plots:

Answer 9

Question 10

True or False: Like a spreadsheet or Excel sheet, a DataFrame object contains an ordered collection of columns. Each column consists of a unique data type, but different columns can have different types, e.g. the first column may consist of integers, while the second one consists of boolean values and so on.

Answer 10

Question 11

True or False: A DataFrame object can be created by concatenating two or more Series objects.

Answer 11

Question 12

True or False: True or False: A DataFrame object has its own built-in plot method.

Answer 12

Question 13

True or False: The kinds of plots that can be created by the DataFrame plot method are the same as the kinds of plots that can be created by the Series plot method.

Answer 13

Question 14

True or False: Pandas provides support for reading datasets in a variety of formats, including:

Answer 14

Question 15

True or False: The method named pandas.read_csv can only read files having a .csv extension.

Answer 15

Question 16

True or False: The DataFrame.head method will display the first five rows of a DataFrame object by default. The number of rows displayed can be changed by specifying the number of rows as an input argument.

Answer 16

Question 17

True or False: By default, when loading a dataset by calling the pandas.read_csv method, the row index for the resulting DataFrame object is a zero-based numeric index. One of the columns of the DataFrame can be used as the row index by passing an argument named row_index to the method specifying the column to be used as the row index.

Answer 17

Question 18

True or False: A DataFrame object can be called by calling the dataframe.transposition method on the object.

Answer 18

Question 19

True or False: We can create a Pandas Series object with default numeric indices by calling the pandas.Series.constructor and passing a list of data values as an argument as shown below.

aSeries = pd.Series(['Tom','Dick','Harry'])

Answer 19

Question 20

True or False: The following code shows how to create a Series object with specified values for both the index and the data.

ageIndex = ['Tom','Dick','Harry']
ageValues = [39,42,65]
ageSeries = pd.Series(ageIndex,ageValues)

Answer 20

Question 21

True or False: The following code shows how to create a Series object with specified values for both the index and the data.

ageIndex = ['Tom','Dick','Harry','Tom']
ageValues = [39,42,65,15]
ageSeries = pd.Series(index=ageIndex,data=ageValues,)

Answer 21

Question 22

True or False: The following code shows how to create a Series object.

aDict = {'Tom':32,'Dick':65,'Harry':21}
ageSeries = pd.Series(aDict)

Answer 22

Question 23

True or False: Series objects can be added to one another.

Answer 23

Question 24

True or False: The Series.iloc method can be used to access data by label(s) or a boolean array, whereas the Series.loc method provides integer-location based or boolean indexing for selection by position.

Answer 24

Question 25

True or False: You can perform scalar operations, such as multiplying a Series object by a constant or adding a constant to a Series object using code such as the following:

ageIndex = ['Tom','Dick','Harry','Tom']
ageValues = [10,20,30,40]
ageSeries = pd.Series(index=ageIndex,data=ageValues,)
ageSeries = ageSeries + 2
ageSeries = ageSeries * 2

The operation is applied to each data element in the object.

Answer 25

Question 26

True or False: You can apply mathematical functions to a Series object using code such as the following, causing the function to applied to each data element in the object.

ageIndex = ['Tom','Dick','Harry','Tom']
ageValues = [10,20,30,40]
ageSeries = pd.Series(index=ageIndex,data=ageValues,)
ageSeries = np.sqrt(ageSeries)

Answer 26

Question 27

True or False: Once you have a Pandas Series object, there are many methods that you can call on the object such as abs, add, apply, and sister.

Answer 27

Question 28

True or False: The Series.apply method must be used to call a specified function on a Pandas Series object,

Answer 28

Question 29

True or False: The Series.apply method can be used with lambda functions.

Answer 29

Question 30

True or False: A Pandas Series object, as well as a Pandas DataFrame object can have data missing from one or more cells. When this happens, that cell is flagged with NaN,

Answer 30

Question 31

True or False: The methods Series.ismissing and Series.notmissing can be used to test for missing data in a Pandas Series object. Similar methods can be used to test for missing data in a Pandas DataFrame object.

Answer 31

Question 32

True or False: The Series.dropna method can be used to remove missing values from a Pandas Series object. The method returns a Pandas Series object containing only non-null data. A similar method can be used to remove missing values from a Pandas DataFrame object.

Answer 32

Question 33

True or False: In some cases, the Series.fillnan method can be used to repair a Pandas Series object that has missing data.

Answer 33

Question 34

True or False: The following code will load a dataset file named MyData.pdq into a Pandas DataFrame object provided that the format of the data in the file meets the requirements of the pandas.read_csv method.

TestData = pd.read_csv('MyData.pdq')

Answer 34

Question 35

True or False: The general syntax for accessing a subset of a Pandas DataFrame object is:

dataFrameObject.loc[startrow:endrow, startcolumn:endcolumn]

Answer 35

Question 36

True or False: The following code writes the contents of the Pandas DataFrame object named TestData12 into an output CSV file named csvOutput.csv.

TestData12.to_csvFile('csvOutput.csv')

Answer 36

 

Answers

Answer 36

False

Explanation

The code should read:

TestData12.to_csv('csvOutput.csv')

The method name was not spelled correctly.

Back to Question 36

Answer 35

True

Back to Question 35

Answer 34

True

Back to Question 34

Answer 33

False.

Explanation

In some cases, the Series.fillna method can be used to repair a Pandas Series object that has missing data. The spelling of the method name is incorrect in the question.

Back to Question 33

Answer 32

True

Back to Question 32

Answer 31

False

Explanation

The methods Series.isnull and Series.notnull can be used to test for missing data in a Pandas Series object. Similar methods can be used to test for missing data in a Pandas DataFrame object.

Back to Question 31

Answer 30

True

Back to Question 30

Answer 29

True

Back to Question 29

Answer 28

False

Explanation

The Series.apply method provides an alternative way to call a specified function on the object. That is not the only way to call a function on the object.

Back to Question 28

Answer 27

False

Explanation

A Pandas Series object does not have a method named sister.

Back to Question 27

Answer 26

True

Back to Question 26

Answer 25

True

Back to Question 25

Answer 24

False.

Explanation

The Series.loc method can be used to access data by label(s) or a boolean array, whereas the Series.iloc method provides integer-location based or boolean indexing for selection by position.

Note that the names of the methods were reversed in the question.

Back to Question 24

Answer 23

True

Back to Question 23

Answer 22

True

Explanation

You can create a Series from a dictionary, in which case we get a Series with the indices sorted.

Back to Question 22

Answer 21

True

Explanation

The data and index arguments can be treated as positional arguments and passed in the order specified by the constructor documentation, or they can be treated as named arguments and entered in a different order.

Back to Question 21

Answer 20

False

Explanation

The code should read as follows. The ageIndex and ageValues arguments were reversed in the code shown earlier.

ageIndex = ['Tom','Dick','Harry']
ageValues = [39,42,65]
ageSeries = pd.Series(ageValues,ageIndex)

Back to Question 20

Answer 19

True

Back to Question 19

Answer 18

False

Explanation

A DataFrame object can be called by calling the dataframe.transpose method on the object.

Back to Question 18

Answer 17

False

Explanation

True or False: By default, when loading a dataset by calling the pandas.read_csv method, the row index for the resulting DataFrame object is a zero-based numeric index. One of the columns of the DataFrame can be used as the row index by passing an argument named index_col to the method specifying the column to be used as the row index.

Back to Question 17

Answer 16

True

Back to Question 16

Answer 15

False

Explanation

Insofar as Pandas is concerned, the file extension doesn't matter. A text file containing tab-separated values could have an extension of .pdq, .txt, .csv, or no extension at all and it would still be treated the same by the pandas.read_csv() method. It is the internal structure and not the file extension that is important in the treatment of the file by the pandas.read_csv() method.

Back to Question 15

Answer 14

False

Explanation

Pandas provides support for reading datasets in a variety of formats, including:

Pandas does not provide a method named pandas.read_jpeg.

Back to Question 14

Answer 13

False

Explanation

The DataFrame plot method adds the following two kinds of plots that are not included in the kinds of plots that can be created by the Series plot method.

See https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html?highlight=dataframe%20plot#pandas.DataFrame.plot

Back to Question 13

Answer 12

True

Explanation

See https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html?highlight=dataframe%20plot#pandas.DataFrame.plot

Back to Question 12

Answer 11

True

Explanation

See https://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html?highlight=pandas%20concat#pandas.concat

Back to Question 11

Answer 10

True

Back to Question 10

Answer 9

False

Explanation

A Series object doesn't have the ability to produce a 'cake' plot. See https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.plot.html?highlight=series%20plot#pandas.Series.plot

Back to Question 9

Answer 8

True

Explanation

See https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.plot.html?highlight=series%20plot#pandas.Series.plot

Back to Question 8

Answer 7

True

Back to Question 7

Answer 6

True

Back to Question 6

Answer 5

False

Explanation

A series can be thought of as a one-dimensional vertical (column) array with an index similar to a Python dictionary. However, unlike the keys in a dictionary, the index values for a Series are not required to be unique.

Back to Question 5

Answer 4

True

Back to Question 4

Answer 3

False

Explanation

Pandas does not provide a BinaryTree data structure.

Back to Question 3

Answer 2

False

Explanation

The Pandas library provides special data structures and operations for the manipulation of numerical tables and time series.

See Introduction into Pandas

Back to Question 2

Answer 1

True

Explanation

See Introduction into Pandas

Back to Question 1

Housekeeping material

Author: Prof. Richard G. Baldwin

Affiliation: Professor of Computer Information Technology at Austin Community College in Austin, TX.

File: PandasReview.htm

Revised: 09/03/18

Copyright 2018 Richard G. Baldwin