Creating Series and DataFrame objects
Most data handling in Python is done using the pandas library, which builds on NumPy to provide R-like structures for holding data. These structures allow the easy indexing of rows and columns, using strings or other Python objects besides just integers. Once data is loaded into a pandas DataFrame
or Series
, it can be easily manipulated, just as if it were in a spreadsheet. This makes Python, when combined with pandas, a powerful tool for processing and analyzing data.
In this recipe, we will see how to create new pandas Series
and DataFrame
objects and access items from them.
Getting ready
For this recipe, we will import the pandas library as pd
using the following command:
import pandas as pd
The NumPy package is np
. We must also create a (seeded) random number generator from NumPy, as follows:
from numpy.random import default_rng rng = default_rng(12345)
How to do it...
The following steps outline how to create Series...