Selecting Subsets of Data in Pandas


single column df[‘food’]
multiple columnsdf[[‘color’, ‘food’, ‘score’]]
single rowdf.loc[‘Niko’]
multiple rowsdf.loc[[‘Niko’, ‘Penelope’]]
slice notation to select a range of rowsdf.loc[‘Niko’:’Dean’]
stepping by 2df.loc[‘Niko’:’Christina’:2]
rows and columnsdf.loc[row_selection, column_selection]
 df.loc[‘Jane’:’Penelope’, [‘state’, ‘color’]]
single rowdf.iloc[3]
multiple rowsdf.iloc[[5, 2, 4]]
 df.iloc[[2,3], [0, 4]]

Leave a comment

Your email address will not be published. Required fields are marked *