Sarah111-AHM / Semsmah

2 stars 0 forks source link

Textbook | pandas 🐼 #25

Closed Sarah111-AHM closed 1 year ago

Sarah111-AHM commented 1 year ago

Series

  1. 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

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. b. Series and DataFrame

  10. b. A one-dimensional array-like object containing a sequence of values and an associated array of data labels

  11. b. An associated array of data labels

  12. b. By passing a Python dict

  13. c. By using labels in square brackets

  14. a. isnull detects missing data while notnull detects non-missing data

  15. c. A float value to represent missing or NA values

  16. d. By index label

  17. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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()

  1. 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

  1. 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

  1. 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]

  1. 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

  1. 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

  1. 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.

  1. 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

  1. 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

  1. 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

  1. 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

  2. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

  1. 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

Answer: c) Yes, duplicates are allowed