Extracting data from pandas

Interacting with pandas is quite easy. In fact, with pandas being built upon NumPy, arrays can easily be extracted from DataFrame objects, and they can be transformed into DataFrames themselves.

First, let's upload some data into a DataFrame. The BostonHouse example we downloaded in the previous chapter from the ML repository is suitable:

In: import pandas as pd    import numpy as np    housing_filename = 'regression-datasets-housing.csv'    housing = pd.read_csv(housing_filename, header=None)

As demonstrated in the Heterogeneous lists section, at this point, the .values method will extract an array of a type that accommodates all the different types that are present in the DataFrame:

In: housing_array = housing.values ...

Get Python Data Science Essentials - Third Edition now with O’Reilly online learning.

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