Pandas Dataframe.iloc - Sheet1 Flashcards
What is pandas.DataFrame.iloc?
DataFrame.iloc is a purely integer-location based indexing for selection by position in pandas DataFrame.
What are some valid inputs for pandas.DataFrame.iloc?
Valid inputs for DataFrame.iloc are:
an integer,
a list or array of integers,
a slice object with integers,
a boolean array,
a callable function with one argument, and a tuple of row and column indexes.
How does DataFrame.iloc handle out-of-bounds indexing?
DataFrame.iloc will raise an IndexError if a requested indexer is out-of-bounds, except slice indexers which allow out-of-bounds indexing according to python/numpy slice semantics.
What happens when you index just the rows with a scalar integer using DataFrame.iloc?
When you index just the rows with a scalar integer, it returns a series representing the row.
What happens when you index just the rows with a list of integers using DataFrame.iloc?
When you index just the rows with a list of integers, it returns a DataFrame representing the selected rows.
What happens when you use a slice object with DataFrame.iloc?
When you use a slice object, DataFrame.iloc returns a DataFrame that includes rows from the start of the slice to the end.
What happens when you use a boolean mask with DataFrame.iloc?
When you use a boolean mask with DataFrame.iloc, it returns a DataFrame containing only the rows for which the mask value is True.
What happens when you use a callable function with DataFrame.iloc?
When you use a callable function, DataFrame.iloc applies the function to the DataFrame and returns the rows for which the function returns True.
How do you index both axes using DataFrame.iloc?
To index both axes with DataFrame.iloc, you can mix the indexer types for the index and columns. Use : to select the entire axis.
What happens when you use scalar integers to index both axes using DataFrame.iloc?
When you use scalar integers to index both axes, DataFrame.iloc returns a scalar value which is the value of the selected cell.
What happens when you use lists of integers to index both axes using DataFrame.iloc?
When you use lists of integers to index both axes, DataFrame.iloc returns a DataFrame with rows and columns that correspond to the selected rows and columns.
What happens when you use slice objects to index both axes using DataFrame.iloc?
When you use slice objects to index both axes, DataFrame.iloc returns a DataFrame that includes rows and columns from the start of the slice to the end.
What happens when you use a boolean array to index both axes using DataFrame.iloc?
When you use a boolean array to index both axes, DataFrame.iloc returns a DataFrame with only the columns for which the mask value is True.
What happens when you use a callable function to index both axes using DataFrame.iloc?
When you use a callable function to index both axes, DataFrame.iloc applies the function to the DataFrame and returns the columns for which the function returns True.
How do DataFrame.iloc and DataFrame.loc differ?
DataFrame.iloc is primarily integer position based, while DataFrame.loc is label-location based indexer for selection by label.
How do DataFrame.iloc and DataFrame.iat differ?
DataFrame.iat is a faster but less flexible version of DataFrame.iloc, which is used for getting or setting a single value in a DataFrame or Series.
How does DataFrame.iloc handle callable input?
DataFrame.iloc handles callable input by passing the DataFrame to the callable function, and the function should return an output that’s valid for indexing.
Can you select every other row in a DataFrame using DataFrame.iloc?
Yes, you can select every other row in a DataFrame using DataFrame.iloc with a callable function like so: df.iloc[lambda x: x.index % 2 == 0].
Can you select the first column in a DataFrame using DataFrame.iloc?
Yes, you can select the first column in a DataFrame using DataFrame.iloc like so: df.iloc[:, 0].