Multi-column selection

To select multiple columns from a DataFrame, we need to pass the columns as a list to the DataFrame as follows:

region_n_state = data[['RegionName', 'State']] 
region_n_state.head() 

Now, let's confirm whether the resulting object is a series or a DataFrame by using the type function, as follows:

type(region_n_state)

Following is the output:

As can be seen in the preceding screenshot, selecting multiple columns creates another DataFrame, whereas selecting just a single column creates a series object.

Get Mastering Exploratory Analysis with pandas now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.