How to do it...

Selecting the data in specific columns of a DataFrame is performed by using the [] operator. This differs from a Series, where [] specifies rows. The [] operator can be passed either a single object or a list of objects representing the columns to retrieve.

The following retrieves the column with the name Sector:

When a single column is retrieved from a DataFrame, the result is a Series:

Multiple columns can be retrieved by specifying a list of column names:

Since this has multiple columns, the result is a DataFrame instead of a Series:

Columns can also be retrieved by attribute access. A DataFrame can have properties added that represent the names of each column, as long as the name does not contain spaces. The following retrieves the Price column in this manner:

Note that this will not work for the Book Value column, as the name has a space.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset