Grabbing subsets of the data
So far, we have learned how to work with and summarize the data as a whole; however, we will often be interested in performing operations and/or analyses on subsets of our data. There are many types of subsets we may look to isolate from our data, such as selecting only specific columns or rows as a whole or when a specific criterion is met. In order to obtain subsets of the data, we need to be familiar with selection, slicing, indexing, and filtering.
For this section, we will work in the 5-subsetting_data.ipynb
notebook. Our setup is as follows:
>>> import pandas as pd >>> df = pd.read_csv('data/earthquakes.csv')
Selecting columns
In the previous section, we saw an example of column selection when we looked at the unique values in the alert
column; we accessed the column as an attribute of the dataframe. Remember that a column is a Series
object, so, for example, selecting the mag
column in the earthquake data gives...