Curriculum
Course: Pandas
Login
Text lesson

Pandas Series

What is a Series?

A Pandas Series is similar to a column in a table and is a one-dimensional array that can store data of any type.

Example

You can create a simple Pandas Series from a list like this:

import pandas as pd

a = [172]

myvar = pd.Series(a)

print(myvar)

Labels

By default, the values are labeled with their index number, starting with 0 for the first value, 1 for the second, and so on. This index can be used to access specific values.

Example

To retrieve the first value of the Series:

print(myvar[0])

Create Labels

The index argument allows you to define custom labels for the values.

Example

Define your own labels:

import pandas as pd

a = [172]

myvar = pd.Series(a, index = [“x”“y”“z”])

print(myvar)

Once you have created labels, you can access an item by referencing its label.

Example

Retrieve the value associated with the label “y”:

print(myvar[“y”])