Pandas Series

  • Learn Pandas Series to manage one-dimensional labeled data in Python.
  • What is a Series?

    A Pandas Series is a one-dimensional array-like object that can store:

    • Numbers

    • Strings

    • Booleans

    • Dates

    • Mixed data types

    Each value in a Series has a label called an index.

    Key Characteristics

    • One-dimensional

    • Has labels (index)

    • Can hold different data types

    • Built on top of NumPy arrays

    Simple Example

import pandas as pd

data = [10, 20, 30, 40]
s = pd.Series(data)

print(s)
  • Creating a Series

    Creating Series from a List

pd.Series([5, 15, 25])
  • Creating Series with Custom Index

pd.Series([100, 200, 300], index=["A", "B", "C"])
  • Creating Series from a Dictionary

scores = {"Math": 85, "Science": 90, "English": 88}
pd.Series(scores)
  • Creating Series with Scalar Value

pd.Series(5, index=["a", "b", "c"])
  • Series Attributes

    Common Attributes

    🔹 index

    Returns the labels of the Series.

s.index
  • 🔹 values

    Returns the data as a NumPy array.

s.values
  • 🔹 dtype

    Returns the data type of the Series.

s.dtype
  • Why Attributes Matter
    • Help understand structure

    • Useful for debugging

    • Important during data preprocessing

    Basic Operations on Series

    Arithmetic Operations

s + 10
s * 2
  • Operations Between Series

s1 = pd.Series([10, 20, 30])
s2 = pd.Series([5, 10, 15])
s1 + s2
  • Pandas aligns values based on index labels, not position.

    Example – Index Alignment

a = pd.Series([10, 20], index=["x", "y"])
b = pd.Series([5, 15], index=["y", "z"])
a + b
  • Filtering Series

s[s > 20]
  • Checking Missing Values

s.isnull()
s.notnull()
  • Real-World Use Cases

    • Storing single column data

    • Time-series analysis

    • Feature values in ML

    • Data cleaning & filtering