![]() | Series |
In pandas, “a Series is a one-dimensional, array-like object containing a sequence of values...and an associated array of data labels, called its index” (McKinney, 126). At first glance, a Series looks a lot like a Python list.
A few notes on what’s happening in this example:
We imported the
pandaspackage (using thepdalias) as well as the specificSeriesandDataFramecomponents.We created a
Seriesobject containing four integer values.
We could create a list with these values, but for data analysis we needed the functionality pandas provides for working with series. To verify obj is stored as an array-like object, we can use pd.Series(obj).values which should return array([4, 7, -5, 3])
Python Examples¶
We can also use Python’s built-in arithmetic functionality for values in a Series object.
# select values in the Series that meet a specific condition
obj2[obj2 > 0]
# returns index-value pairs for values greater than 0# multiply all values in Series
obj * 2
# returns modified valuesTry to perform similar mathematical operations on values stored in a Python dictionary or list and you’ll run into all kinds of data type errors. The Series object uses a similar data structure and opens up a wide range of analysis possibilities.
Application¶
Q1: Create your own Series object. Write code the accomplishes the following tasks. Your answer for these items should include a Python program + comments that document process and explain your code.
Perform at least two unique arithmetic operations on the Series
Test for null values in your series
