O'Reilly logo

Mastering pandas for Finance by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required