Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Series
What DataFrames are
DataFrame columns
DataFrame rows
Filtering rows and columns
23. Filtering rows and columns with loc
Filtering data frames
Sorting rows
Summary

Instruction

Great! Apart from filtering rows by index, you can use the loc function in order to filter rows by index, and columns by name at the same time. For example, you can select the first five rows only from the Hospital Name column:

hospitals.loc[0:4, 'Hospital Name']

You can also provide a list of column names you want to select:

hospitals.loc[0:4, ['Hospital Name', 'City']]

Remember that you always have to put the names of the columns in quotes.

Exercise

Display the data from the 3rd through 8th row of the eu_states DataFrame. However, show the results only for the Country and Currency columns (in that order).