Series

What is a Series?

A series is a straightforward one-dimensional Pandas object that is created with indicies. As with many coding langugages there are lots of different ways to create a one-dimensional array. The benefit of a series object is that it comes with all of the additional Pandas functionality built in!

my_first_series = pd.Series([5, 10, 15, 20], index=['a', 'b', 'c', 'd'])
print(my_first_series['c'])
15

You can also create a series without passing the index argument. This will result in a Pandas series with the default 0-indexed values:

my_second_series = pd.Series([5, 10, 15, 20])
print(my_second_series[2])
15

You may not use series directly very often, but it’s helpful to know of the different types of data structures that are available as part of Pandas. When writing new code you should double check that your data structure fits your use case.

You can also utilize many of the other Pandas functions that you’ll learn about in this section in conjuction with a series object. For example, in the code below we can utilize the Pandas function idxmax to identify the index of the largest value in the series.

long_list = np.random.randint(low=1, high=10000, size=100)
long_series = pd.Series(long_list)
biggest_value_index = long_series.idxmax()
print(long_series[biggest_value_index])

Resources

The Pandas documentation also gives a great overview of series in their 10 minute walkthrough.