Selecting Using .loc[]

Unordered Indexing

cereal
name mfr type calories ... shelf weight cups rating
0 100% Bran N Cold 70 ... 3 1.0 0.33 68.402973
1 100% Natural Bran Q Cold 120 ... 3 1.0 1.00 33.983679
2 All-Bran K Cold 70 ... 3 1.0 0.33 59.425505
... ... ... ... ... ... ... ... ... ...
74 Wheat Chex R Cold 100 ... 1 1.0 0.67 49.787445
75 Wheaties G Cold 100 ... 1 1.0 1.00 51.592193
76 Wheaties Honey Gold G Cold 110 ... 1 1.0 0.75 36.187559

77 rows × 16 columns

cereal.loc[[13,73,75], ['name', 'type', 'sugars', 'rating']]
name type sugars rating
13 Clusters Cold 7 40.400208
73 Trix Cold 12 27.753301
75 Wheaties Cold 3 51.592193


cereal.loc[[75, 73, 13], ['name', 'type', 'rating', 'sugars']]
name type rating sugars
75 Wheaties Cold 51.592193 3
73 Trix Cold 27.753301 12
13 Clusters Cold 40.400208 7

Let’s apply what we learned!