Getting Started with pandas
50 questions available
Questions
What is the fundamental structure of a pandas Series?
View answer and explanationWhat is one of the most common ways to construct a pandas DataFrame?
View answer and explanationGiven the code `sdata = {"Ohio": 35000, "Texas": 71000, "Oregon": 16000, "Utah": 5000}` and `states = ["California", "Ohio", "Oregon", "Texas"]`, what will be the value associated with the 'California' index when creating a Series with `pd.Series(sdata, index=states)`?
View answer and explanationWhat is a key characteristic of pandas Index objects as described in the text?
View answer and explanationWhat is the primary purpose of the `reindex` method on pandas objects?
View answer and explanationGiven `obj3 = pd.Series(["blue", "purple", "yellow"], index=[0, 2, 4])`, what will be the value at index 3 after executing `obj3.reindex(np.arange(6), method="ffill")`?
View answer and explanationIn a DataFrame named `data`, which of the following is a correct way to drop a column named 'two' and return a new DataFrame?
View answer and explanationWhat is the primary difference between the `.loc` and `.iloc` accessors on a pandas object?
View answer and explanationWhy is it advisable to avoid chained indexing like `data.loc[data.three == 5]["three"] = 6` when assigning values in pandas?
View answer and explanationGiven `s1 = pd.Series([7.3, -2.5, 3.4, 1.5], index=["a", "c", "d", "e"])` and `s2 = pd.Series([-2.1, 3.6, -1.5, 4], index=["a", "c", "e", "f"])`, what is the value at index 'd' in the result of `s1 + s2`?
View answer and explanationIn arithmetic operations between two differently indexed DataFrames, what is the purpose of the `fill_value` argument in a method like `df1.add(df2, fill_value=0)`?
View answer and explanationBy default, when you perform an arithmetic operation between a DataFrame and a Series, how does pandas align the two objects?
View answer and explanationWhat is the result of using the `.apply()` method on a DataFrame without specifying an axis?
View answer and explanationWhich method should be used to apply a function to every single element in a DataFrame?
View answer and explanationTo sort a DataFrame lexicographically by its column labels, which method should be used?
View answer and explanationGiven `obj = pd.Series([7, -5, 7, 4, 2, 0, 4])`, what is the rank of the first element (value 7) when using `obj.rank(method="first")`?
View answer and explanationWhat is the result of indexing a Series that has duplicate index labels with a label that appears multiple times?
View answer and explanationHow does the `.describe()` method behave when called on a DataFrame column containing non-numeric data, such as strings?
View answer and explanationGiven `df = pd.DataFrame([[1.4, np.nan], [7.1, -4.5], [np.nan, np.nan], [0.75, -1.3]], index=["a", "b", "c", "d"], columns=["one", "two"])`, what is the result of `df.sum(axis="columns")` for the row with index 'c'?
View answer and explanationWhat is the primary function of the `corrwith` method in pandas?
View answer and explanationWhen you create a DataFrame `frame2 = pd.DataFrame(data, columns=["year", "state", "pop", "debt"])` where 'debt' is not a key in the `data` dictionary, what will be the data type of the 'debt' column?
View answer and explanationWhat is a key limitation of accessing a DataFrame column using dot attribute notation (e.g., `frame2.year`)?
View answer and explanationWhen assigning a Series to a DataFrame column, what happens if the Series's index does not align with the DataFrame's index?
View answer and explanationHow can you create a DataFrame from a nested dictionary of dictionaries, like `populations = {"Ohio": {2000: 1.5}, "Nevada": {2001: 2.4}}`?
View answer and explanationWhat is the result of `frame2.to_numpy()` if the DataFrame `frame2` contains columns of different data types, such as integers and strings?
View answer and explanationAccording to Table 5-2, 'Some Index methods and properties', what does the `isin()` method do?
View answer and explanationIf you reindex a DataFrame using the `.loc` operator, what is a key requirement for the new index labels you provide?
View answer and explanationSlicing a Series with labels using `.loc`, such as `obj2.loc["b":"c"]`, works differently from normal Python slicing. What is this difference?
View answer and explanationWhen indexing a DataFrame with a Boolean DataFrame, such as in `data[data < 5] = 0`, what happens?
View answer and explanationAccording to Table 5-5 'Flexible arithmetic methods', which method is the reverse of `sub` (for subtraction)?
View answer and explanationIf you want to perform an arithmetic operation between a DataFrame and a Series by matching the Series index on the DataFrame's row index, what must you do?
View answer and explanationAccording to Table 5-6, 'Tie-breaking methods with rank', what does the `method="min"` do?
View answer and explanationWhat does the pandas `value_counts()` method return?
View answer and explanationWhat is the function of the `isin` method on a pandas Series?
View answer and explanationWhat is the purpose of the `skipna` option in reduction methods like `sum()`?
View answer and explanationHow do the `argmin` and `idxmin` methods differ?
View answer and explanationWhat is a major feature of a pandas Series that is useful in arithmetic operations, as stated in Chapter 5.2?
View answer and explanationWhat does the `.T` attribute on a DataFrame object do?
View answer and explanationWhen you have data in a Python dictionary, how does the resulting Series created from it determine the order of the index?
View answer and explanationWhat is the return type of selecting a single row from a DataFrame using an accessor like `data.loc["Colorado"]`?
View answer and explanationWhat do the `isna` and `notna` functions in pandas do?
View answer and explanationWhen adding two DataFrames `df1 + df2`, what are the index and columns of the resulting DataFrame?
View answer and explanationWhat is the behavior of the `sort_values` method on a Series that contains missing (NaN) values?
View answer and explanationGiven `obj = pd.Series(np.arange(4.), index=["a", "b", "c", "d"])`, what is the result of `obj[obj < 2]`?
View answer and explanationWhat is the reason given in the text to prefer using `loc` or `iloc` over standard `[]` indexing for a Series with an integer index?
View answer and explanationIn a DataFrame, how can you select the rows where the value in the 'three' column is greater than 5?
View answer and explanationIf you add two DataFrame objects that have no column or row labels in common, what will the resulting DataFrame contain?
View answer and explanationWhen sorting a DataFrame by multiple columns, such as `frame.sort_values(["a", "b"])`, how is the sort performed?
View answer and explanationBoth the Series object itself and its index have what attribute that integrates with other areas of pandas functionality?
View answer and explanationGiven `data = pd.DataFrame(np.arange(16).reshape((4, 4)), index=["Ohio", "Colorado", "Utah", "New York"])`, what is the result of `data.iloc[2]`?
View answer and explanation