What are the two main data structures in pandas?
a. List and Tuple
b. Series and DataFrame
c. Dictionary and Set
d. String and Integer
What is a Series in pandas?
a. A two-dimensional array-like object containing labeled axes
b. A one-dimensional array-like object containing a sequence of values and an associated array of data labels
c. A three-dimensional array-like object containing labeled axes
d. A four-dimensional array-like object containing labeled axes
What is the index of a Series?
a. A sequence of values
b. An associated array of data labels
c. A two-dimensional array-like object
d. A three-dimensional array-like object
How can you create a Series with an index?
a. By passing only an array of data
b. By passing a Python dict
c. By passing a list of indices
d. By passing both an array of data and a list of indices
How can you select values from a Series using labels in the index?
a. By using integer indices
b. By using a list of indices
c. By using labels in square brackets
d. By using boolean arrays
What is the difference between isnull and notnull functions in pandas?
a. isnull detects missing data while notnull detects non-missing data
b. isnull and notnull are the same functions
c. isnull and notnull detect missing data
d. isnull detects non-missing data while notnull detects missing data
What is NaN in pandas?
a. A string value to represent missing data
b. A boolean value to represent missing data
c. A float value to represent missing or NA values
d. A special data type in pandas to represent missing data
How does pandas align data in arithmetic operations?
a. By using integer indices
b. By using a list of indices
c. By using labels in square brackets
d. By index label
b. Series and DataFrame
b. A one-dimensional array-like object containing a sequence of values and an associated array of data labels
b. An associated array of data labels
b. By passing a Python dict
c. By using labels in square brackets
a. isnull detects missing data while notnull detects non-missing data
c. A float value to represent missing or NA values
d. By index label
What is a DataFrame?
a) A rectangular table of data
b) A collection of one-dimensional arrays
c) A dictionary of Series
d) A list of values
Answer: a) A rectangular table of data
What types of values can a DataFrame contain?
a) Only numeric values
b) Only string values
c) Only boolean values
d) Any combination of value types
Answer: d) Any combination of value types
What is the row and column index of a DataFrame?
a) Only a row index
b) Only a column index
c) Both a row and column index
d) Neither a row nor column index
Answer: c) Both a row and column index
How is data stored in a DataFrame?
a) As a list
b) As a dictionary
c) As one or more two-dimensional blocks
d) As a collection of one-dimensional arrays
Answer: c) As one or more two-dimensional blocks
How can a DataFrame represent higher dimensional data?
a) By using one-dimensional arrays
b) By using a collection of Series
c) By using hierarchical indexing
d) By using a list of values
Answer: c) By using hierarchical indexing
What is one of the most common ways to construct a DataFrame?
a) From a dictionary of equal-length lists or NumPy arrays
b) From a list of values
c) From a collection of one-dimensional arrays
d) From a dictionary of unequal-length lists or NumPy arrays
Answer: a) From a dictionary of equal-length lists or NumPy arrays
How is the index assigned to a DataFrame that is constructed from a dictionary?
a) It is assigned in alphabetical order
b) It is assigned in reverse alphabetical order
c) It is assigned automatically
d) It is assigned based on the order of the keys in the dictionary
Answer: c) It is assigned automatically
In what order are the columns placed in a DataFrame that is constructed from a dictionary?
a) In the order specified in the dictionary
b) In reverse order
c) In alphabetical order
d) In sorted order
Answer: d) In sorted order
What method can be used to select only the first five rows of a large DataFrame?
a) tail()
b) select()
c) head()
d) first()
Answer: c) head()
What happens if you pass a column that isn’t contained in the dictionary when constructing a DataFrame?
a) An error is raised
b) The column is added to the DataFrame with no missing values
c) The column is added to the DataFrame with missing values
d) The DataFrame is not constructed
Answer: c) The column is added to the DataFrame with missing values
What is the purpose of the Index method in the DataFrame?
a) To retrieve the DataFrame's index
b) To retrieve the DataFrame's columns
c) To retrieve a specific value in the DataFrame
d) To retrieve a specific row in the DataFrame
Answer: a) To retrieve the DataFrame's index
How can a column in a DataFrame be retrieved as a Series using dict-like notation?
a) frame2.column
b) frame2[column]
c) frame2{column}
d) frame2.column()
Answer: b) frame2[column]
How can a column in a DataFrame be retrieved as a Series using attribute-like access?
a) frame2[column]
b) frame2.column
c) frame2{column}
d) frame2.column()
Answer: b) frame2.column
What is the name attribute of a returned Series?
a) It is the column name
b) It is the index name
c) It is the same as the DataFrame name
d) It is not set by default
Answer: a) It is the column name
How can rows be retrieved from a DataFrame?
a) By using the loc attribute
b) By using the iloc attribute
c) By using the name of the row
d) All of the above
Answer: d) All of the above. Rows can be retrieved using the loc attribute, the iloc attribute, or the name of the row.
How can a specific row in a DataFrame be retrieved using the loc attribute?
a) By using the row's index label
b) By using the row's position
c) By using the row's column name
d) By using both a and b
Answer: a) By using the row's index label
How can a column in a DataFrame be modified?
a) By using the Index method
b) By using the loc attribute
c) By assignment
d) By using the iloc attribute
Answer: c) By assignment
What happens if you assign a list or array to a column in a DataFrame and the value's length does not match the length of the DataFrame?
a) An error is raised
b) The assignment is successful, but the excess values are discarded
c) The assignment is successful, but missing values are inserted in any holes
d) The DataFrame is not modified
Answer: a) An error is raised
What happens if you assign a Series to a column in a DataFrame and the Series' labels do not match the DataFrame's index?
a) An error is raised
b) The assignment is successful, but the excess labels are discarded
c) The assignment is successful, but missing values are inserted in
How can a specific row in a DataFrame be retrieved using the loc attribute?
a) By using the row's index label
b) By using the row's position
c) By using the row's column name
d) By using both a and b
Answer: a) By using the row's index label
How can a column in a DataFrame be modified?
a) By using the Index method
b) By using the loc attribute
c) By assignment
d) By using the iloc attribute
Answer: c) By assignment
What happens if you assign a list or array to a column in a DataFrame and the value's length does not match the length of the DataFrame?
a) An error is raised
b) The assignment is successful, but the excess values are discarded
c) The assignment is successful, but missing values are inserted in any holes
d) The DataFrame is not modified
Answer: a) An error is raised
What happens if you assign a Series to a column in a DataFrame and the Series' labels do not match the DataFrame's index?
a) An error is raised
b) The assignment is successful, but the excess labels are discarded
c) The assignment is successful, but missing values are inserted in any holes
d) The DataFrame is not modified
Answer: c) The assignment is successful, but missing values are inserted in any holes
What happens when you assign a value to a column that doesn't exist in a DataFrame?
a) An error is raised
b) A new column is created with the assigned value
c) The DataFrame is not modified
d) The existing column with the same name is overwritten
Answer: b) A new column is created with the assigned value
How can a column be deleted from a DataFrame?
a) By using the Index method
b) By using the del keyword
c) By using the loc attribute
d) By using the iloc attribute
Answer: b) By using the del keyword
Is the column returned from indexing a DataFrame a view or a copy of the data?
a) It is a copy of the data
b) It is a view on the underlying data
c) It depends on the size of the DataFrame
d) It depends on the type of data in the column
Answer: b) It is a view on the underlying data
How can a nested dict of dicts be converted to a DataFrame?
a) By passing the outer dict to the DataFrame, with the inner dicts as values
b) By passing the inner dicts to the DataFrame, with the outer dicts as values
c) By using the Index method
d) By using the iloc attribute
Answer: a) By passing the outer dict to the DataFrame, with the inner dicts as values
What happens if the nested dict passed to a DataFrame has missing values?
a) An error is raised
b) The missing values are replaced with NaN
c) The DataFrame is not created
d) The missing values are replaced with the previous non-missing value
Answer: b) The missing values are replaced with NaN
How can a new column be created in a DataFrame?
a) By using the del keyword
b) By using the Index method
c) By assigning a value to a column that doesn't exist
d) By using the iloc attribute
Answer: c) By assigning a value to a column that doesn't exist
How can a column be deleted from a DataFrame?
a) By using the Index method
b) By using the del keyword
c) By using the loc attribute
d) By using the iloc attribute
Answer: b) By using the del keyword
What is the relationship between a column returned from indexing a DataFrame and the underlying data?
a) It is a copy of the data
b) It is a view on the underlying data
c) It is a completely separate object
d) It depends on the size of the DataFrame
Answer: b) It is a view on the underlying data
How can a Series be copied from a DataFrame column?
a) By using the Index method
b) By using the copy method of the Series
c) By using the loc attribute
d) By using the iloc attribute
Answer: b) By using the copy method of the Series
How does pandas interpret a nested dict of dicts when passed to a DataFrame?
a) The outer dict keys become the row indices and the inner keys become the columns
b) The inner dict keys become the row indices and the outer dict keys become the columns
c) The outer dict keys become the columns and the inner dict keys become the row indices
d) The inner dict keys become the columns and the outer dict keys become the row indices
Answer: c) The outer dict keys become the columns and the inner dict keys become the row indices
What happens to the dtype of the values array if the columns of a DataFrame have different dtypes?
a) The dtype of the first column is used for the entire array
b) The dtype of the last column is used for the entire array
c) The dtype is chosen to accommodate all of the columns
d) An error is raised
Answer: c) The dtype is chosen to accommodate all of the columns
What are the possible data inputs to the DataFrame constructor?
a) Only 2D ndarrays and dicts of Series
b) Only dicts of arrays, lists, or tuples
c) A limited set of data types such as lists, dicts, and ndarrays
d) A variety of data types including ndarrays, dicts of Series, and structured arrays
Answer: d) A variety of data types including ndarrays, dicts of Series, and structured arrays
What happens when a dict of Series is passed to the DataFrame constructor?
a) Each value becomes a row in the DataFrame
b) Each key becomes a column in the DataFrame
c) Each inner dict becomes a column in the DataFrame
d) Each value becomes a column in the DataFrame, with the indexes unioned to form the row index
Answer: d) Each value becomes a column in the DataFrame, with the indexes unioned to form the row index
What happens when a list of dicts or Series is passed to the DataFrame constructor?
a) Each dict becomes a row in the DataFrame
b) Each value becomes a column in the DataFrame, with the keys unioned to form the row index
c) Each item becomes a row in the DataFrame, with the keys unioned to form the column labels
d) An error is raised
Answer: a) Each dict becomes a row in the DataFrame
What happens when a NumPy MaskedArray is passed to the DataFrame constructor?
a) The masked values are filled with NaN in the resulting DataFrame
b) The masked values are removed from the resulting DataFrame
c) An error is raised
d) The masked values are preserved in the resulting DataFrame
Answer: a) The masked values are filled with NaN in the resulting DataFrame
What is the purpose of pandas's Index objects?
a) To hold the data contained in a DataFrame or Series
b) To hold the axis labels and other metadata
c) To provide a way to modify the data in a DataFrame or Series
d) To provide a way to subset the data in a DataFrame or Series
Answer: b) To hold the axis labels and other metadata
Can Index objects be modified by the user?
a) Yes, they can be modified in place
b) Yes, but only certain methods can be used to modify them
c) No, they are immutable and cannot be modified by the user
d) No, they are mutable but it is not recommended to modify them
Answer: c) No, they are immutable and cannot be modified by the user
Why is immutability important for Index objects?
a) It makes it easier to modify the data contained in a DataFrame or Series
b) It makes it safer to share Index objects among data structures
c) It allows for better performance when working with large datasets
d) It ensures that the Index objects are always sorted
Answer: b) It makes it safer to share Index objects among data structures
How does an Index behave?
a) Like a list
b) Like a set
c) Like a dictionary
d) Like a NumPy array
Answer: b) Like a set
Can an Index contain duplicate labels?
a) No, duplicates are not allowed
b) Yes, but only if they are of different data types
c) Yes, duplicates are allowed
d) Yes, but only if they are explicitly allowed by the user
Series
What are the two main data structures in pandas? a. List and Tuple b. Series and DataFrame c. Dictionary and Set d. String and Integer
What is a Series in pandas? a. A two-dimensional array-like object containing labeled axes b. A one-dimensional array-like object containing a sequence of values and an associated array of data labels c. A three-dimensional array-like object containing labeled axes d. A four-dimensional array-like object containing labeled axes
What is the index of a Series? a. A sequence of values b. An associated array of data labels c. A two-dimensional array-like object d. A three-dimensional array-like object
How can you create a Series with an index? a. By passing only an array of data b. By passing a Python dict c. By passing a list of indices d. By passing both an array of data and a list of indices
How can you select values from a Series using labels in the index? a. By using integer indices b. By using a list of indices c. By using labels in square brackets d. By using boolean arrays
What is the difference between isnull and notnull functions in pandas? a. isnull detects missing data while notnull detects non-missing data b. isnull and notnull are the same functions c. isnull and notnull detect missing data d. isnull detects non-missing data while notnull detects missing data
What is NaN in pandas? a. A string value to represent missing data b. A boolean value to represent missing data c. A float value to represent missing or NA values d. A special data type in pandas to represent missing data
How does pandas align data in arithmetic operations? a. By using integer indices b. By using a list of indices c. By using labels in square brackets d. By index label
b. Series and DataFrame
b. A one-dimensional array-like object containing a sequence of values and an associated array of data labels
b. An associated array of data labels
b. By passing a Python dict
c. By using labels in square brackets
a. isnull detects missing data while notnull detects non-missing data
c. A float value to represent missing or NA values
d. By index label
What is a DataFrame? a) A rectangular table of data b) A collection of one-dimensional arrays c) A dictionary of Series d) A list of values
Answer: a) A rectangular table of data
Answer: d) Any combination of value types
Answer: c) Both a row and column index
Answer: c) As one or more two-dimensional blocks
Answer: c) By using hierarchical indexing
Answer: a) From a dictionary of equal-length lists or NumPy arrays
Answer: c) It is assigned automatically
Answer: d) In sorted order
Answer: c) head()
Answer: c) The column is added to the DataFrame with missing values
Answer: a) To retrieve the DataFrame's index
Answer: b) frame2[column]
Answer: b) frame2.column
Answer: a) It is the column name
Answer: d) All of the above. Rows can be retrieved using the loc attribute, the iloc attribute, or the name of the row.
Answer: a) By using the row's index label
Answer: c) By assignment
Answer: a) An error is raised
What happens if you assign a Series to a column in a DataFrame and the Series' labels do not match the DataFrame's index? a) An error is raised b) The assignment is successful, but the excess labels are discarded c) The assignment is successful, but missing values are inserted in
How can a specific row in a DataFrame be retrieved using the loc attribute? a) By using the row's index label b) By using the row's position c) By using the row's column name d) By using both a and b
Answer: a) By using the row's index label
Answer: c) By assignment
Answer: a) An error is raised
Answer: c) The assignment is successful, but missing values are inserted in any holes
Answer: b) A new column is created with the assigned value
Answer: b) By using the del keyword
Answer: b) It is a view on the underlying data
Answer: a) By passing the outer dict to the DataFrame, with the inner dicts as values
Answer: b) The missing values are replaced with NaN
Answer: c) By assigning a value to a column that doesn't exist
Answer: b) By using the del keyword
Answer: b) It is a view on the underlying data
Answer: b) By using the copy method of the Series
Answer: c) The outer dict keys become the columns and the inner dict keys become the row indices
Answer: c) The dtype is chosen to accommodate all of the columns
Answer: d) A variety of data types including ndarrays, dicts of Series, and structured arrays
Answer: d) Each value becomes a column in the DataFrame, with the indexes unioned to form the row index
Answer: a) Each dict becomes a row in the DataFrame
Answer: a) The masked values are filled with NaN in the resulting DataFrame
Answer: b) To hold the axis labels and other metadata
Answer: c) No, they are immutable and cannot be modified by the user
Answer: b) It makes it safer to share Index objects among data structures
Answer: b) Like a set
Answer: c) Yes, duplicates are allowed