← Back to Python

All Topics

Advertisement

Learn/Python/Data Science

Pandas Series

Topic: Pandas

Advertisement

Introduction

Series is a one-dimensional labeled array capable of holding any data type.

Creating Series

import pandas as pd

# From list
s = pd.Series([1, 3, 5, 7])

# With custom index
s = pd.Series([1, 3, 5], index=["a", "b", "c"])

# From dictionary
s = pd.Series({"a": 1, "b": 3, "c": 5})

# With datetime index
dates = pd.date_range("2024-01-01", periods=5)
s = pd.Series([10, 20, 30, 40, 50], index=dates)

Series Operations

s = pd.Series([1, 2, 3, 4, 5])

# Indexing
s[0]
s["a"]
s[1:3]
s[s > 2]

# Math operations
s + 10
s * 2
s ** 2

# Aggregation
s.sum()
s.mean()
s.std()
s.describe()

Practice Problems

  1. Create Series with datetime index
  2. Select by position and label
  3. Filter Series values
  4. Calculate cumulative sums
  5. Align Series by index

Advertisement

Advertisement

Need More Practice?

Get personalized Python help from ChatWhole's AI-powered platform.

Get Expert Help →