cereal.loc[:, 'calories':'fiber']| calories | protein | fat | sodium | fiber | |
|---|---|---|---|---|---|
| 0 | 70 | 4 | 1 | 130 | 10.0 |
| 1 | 120 | 3 | 5 | 15 | 2.0 |
| 2 | 70 | 4 | 1 | 260 | 9.0 |
| ... | ... | ... | ... | ... | ... |
| 74 | 100 | 3 | 1 | 230 | 3.0 |
| 75 | 100 | 3 | 1 | 200 | 3.0 |
| 76 | 110 | 2 | 1 | 200 | 1.0 |
77 rows × 5 columns
.loc[] is used to slice columns and rows by label and within an interval.
We always specify row indexing first, then columns.
: followed by interval of the columns:We can read : as “to”.
If the indices are labeled with numbers, we do not need “quotations” when calling them. This is only when the labels are using letters.