Creating DataFrame from scratch
To use a DataFrame we first need to import pandas and set some options for output.
In [1]: # reference NumPy and pandas import numpy as np import pandas as pd # Set some pandas options pd.set_option('display.notebook_repr_html', False) pd.set_option('display.max_columns', 10) pd.set_option('display.max_rows', 10)
There are several ways to create a DataFrame. Probably the most straightforward way, is by creating it from a NumPy array. The following code creates a DataFrame from a two dimensional NumPy array.
In [2]: # create a DataFrame from a 2-d ndarray pd.DataFrame(np.array([[10, 11], [20, 21]])) Out[2]: 0 1 0 10 11 1 20 21
Each row of the array forms a row in the DataFrame object. Since we did not specify an index, pandas creates a default int64 index in the same manner as a Series object. Since we did not specify column names, pandas also assigns the names for each column with...