Pandas Series

Python · Pandas Basics

Theory

A pandas Series is a one-dimensional array of values with a label for each position, called the index. pd.Series([100, 250, 300], index=['Jan', 'Feb', 'Mar']) stores three sales figures labelled by month, so sales['Feb'] returns 250. If you do not give an index, pandas uses 0, 1, 2 and so on. Every Series also has a dtype (int64 here) and an optional name.

A Series behaves like a NumPy array with labels: sales * 2 doubles every value, sales.sum() adds them, and sales[sales > 150] filters with a boolean mask, returning Feb 250 and Mar 300 with their labels kept. When two Series are combined, pandas aligns them by index label, not position, and labels present in only one give NaN. Each column of a DataFrame is a Series.

Why we use it

Labels make data self-describing: you work with sales['Feb'] instead of remembering that February is position 1. Alignment by label prevents silent mistakes when combining data from different sources.

When to use it

Use a Series for a single column of data or a labelled list of values, such as monthly totals. When you have several related columns, use a DataFrame; for plain numeric maths with no labels, a NumPy array is lighter.

How it works

  1. pd.Series(values, index=labels)
  2. Pair each value with its index label
  3. Infer one dtype for the values
  4. Computing on values? Yes: Element-wise, aligned by label. No: Look up via sales['Feb'] or .loc.
  5. Labelled result Series

Syntax

pd.Series(data, index=labels, name='col')

Example

import pandas as pd
sales = pd.Series([100, 250, 300], index=['Jan','Feb','Mar'])
print(sales)

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic