Pandas Flashcards
(98 cards)
Select multiple columns of pandas dataframe?
df[[‘column 1’, ‘column 2’]]
What are the three ways to index data in pandas?
df[ ]
df. loc[ ]
df. iloc[ ]
How do you select one column from a dataframe as a series?
df[‘food’]
How do you selection one column from a dataframe as a dataframe?
df[[‘food’]]
How do you select multiple columns from a dataframe?
df[[‘color’, ‘food’, ‘score’]]
Can you change the column order when selecting columns?
Yes
When selecting a column from a dataframe as a series what happens to the column label?
Becomes the name of the series
How do you select rows and columns using .loc?
df.loc[row_selection, column_selection]
How do you select multiple rows and columns using .loc?
df.loc[[‘Dean’, ‘Cornelia’], [‘age’, ‘state’, ‘score’]]
Do you need apotosphes when using list names for selecting rows / columns?
no
Does .loc include the last item?
Yes
What is iloc index on?
Integer index location
What does df.iloc[3] find?
The 4th row
To select multiple rows using integers .iloc what do you have to use?
A list df.iloc[[5, 2, 4]]
How do you slice rows using .iloc?
df.iloc[3:5] (no double bracket required)
Selecting rows and columns using iloc and integreers?
f.iloc[[2,3], [0, 4]]
How do you select rows using a slice and columns using integers using iloc?
df.iloc[3:6, [1, 4]]
What should you use the indexing operator for?
Columns 1) A string - returns a series 2) A list of strings - returns a dataframe Rows 3) A slice 4) Booleans
Can you use the indexing operator to select both rows and columns?
No
Can you use the indexing operator to select rows?
Yes but don’t
How do you set the index after reading in the csv
df.set_index()
What can you use dot notation for?
Selecting a single column
What 2 methods can you use for boolean selection?
[] and .loc
What method can you use to test multiple conditions in the same column?
isin