Pandas Series

A series is a one-dimensional array of data where the rows are labeled.

This recipe includes the following topics:

  • Create a Pandas Series
  • Access Series element
  • Generate descriptive statistics


# import module
import pandas as pd
import numpy as np

# create index for series
rowname = ['Jan', 'Apr', 'Jul', 'Oct']

# create value for series
temperatureVals = np.array([32, 58, 95, 71])

# create Pandas series
temperatureSeries = pd.Series(temperatureVals, index=rowname)

# access series element
print(temperatureSeries[1])
print(temperatureSeries['Apr'])

# display whole series
print(temperatureSeries)

# Generate descriptive statistics
temperatureSeries.describe()
58
58

Jan    32
Apr    58
Jul    95
Oct    71
dtype: int64

count     4.000000
mean     64.000000
std      26.267851
min      32.000000
25%      51.500000
50%      64.500000
75%      77.000000
max      95.000000
dtype: float64

Leave a Reply

Your email address will not be published. Required fields are marked *