Creating DataFrame objects
There are a number of ways to create a data frame. A data frame can be created from either a single or multi-dimensional set of data. The techniques that we will examine are as follows:
- Using the results of NumPy functions
- Using data from a Python dictionary consisting of lists or pandas
Series
objects - Using data from a CSV file
While examining each of these we will also examine how to specify column names, demonstrate how alignment is performed during initialization, and see how to determine the dimensions of a data frame.
Creating a DataFrame using NumPy function results
A data frame can be created from a one-dimensional NumPy array of integers ranging from 1 to 5:

The first column of the output shows the labels of the index that was created. Since an index was not specified at the time of creation, pandas created a based RangeIndex
with labels starting at 0.
The data is in the second column and consists of the values 1
through 5
. The 0
above the column of data is the...