import pandas as pd cereal = pd.read_csv('data/cereal.csv') cereal.head()
5 rows × 16 columns
Attribution: “80 Cereals” (c) by Chris Crawford is licensed under Creative Commons Attribution-ShareAlike 3.0 Unported
cereal.head(15)
15 rows × 16 columns
cereal.loc[5:10]
6 rows × 16 columns
cereal.loc[5:10, 'calories':'fiber']
The general format to slice both rows and columns together looks like this:
cereal.loc['row name start':'row name end', 'column name start':'column name end']
cereal.loc[:6]
7 rows × 16 columns
cereal.loc[:6, 'sugars':]