The basics of the Series and DataFrame objects
Now let's examine using the Series
and DataFrame
objects, building up an understanding of their capabilities that will assist us in working with financial data.
Creating a Series and accessing elements
A Series
can be created by passing a scalar value, a NumPy array, or a Python dictionary/list to the constructor of the Series
object. The following command creates a Series
from 100
normally distributed random numbers:
In [2]: np.random.seed(1) s = pd.Series(np.random.randn(100)) s Out[2]: 0 1.624345 1 -0.611756 2 -0.528172 3 -1.072969 ... 96 -0.343854 97 0.043597 98 -0.620001 99 0.698032 Length: 100, dtype: float64
Individual elements of a Series
can be retrieved using the []
operator of the Series
object. The item with the index label 2
can be retrieved using the following code:
In [3]: s[2] Out[3]: -0.528171752263
Multiple values can be retrieved using an array...