🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Pandas Series and DataFrames

🟢 Free Lesson

Advertisement

Pandas Series and DataFrames

Pandas is the most important library in Python data science. It provides two primary data structures – Series and DataFrame – that make working with structured data intuitive and powerful.

Series

A Series is a one-dimensional labeled array. Think of it as a single column of data with an index.

Series Operations

DataFrame Structure

DataFrame = Series Columns + Indexidx012IndexnameAliceBobCharlieage253035salary700008000090000← Series (column)Each column =a pd.Seriesdf["age"] → pd.Series([25, 30, 35], index=[0,1,2])

DataFrame

A DataFrame is a two-dimensional labeled data structure – like a spreadsheet or SQL table.

Creating DataFrames

Basic Properties

Indexing: loc and iloc

loc accesses by label. iloc accesses by position. Understanding this distinction is critical.

loc vs iloc Cheat Sheet

Architecture Diagram
loc:  Uses labels (index names, column names)
      Slicing is INCLUSIVE on both ends
      df.loc["a":"c"] includes "c"

iloc: Uses integer positions (0, 1, 2...)
      Slicing is EXCLUSIVE on end (like Python)
      df.iloc[0:3] stops at index 2

Selecting Columns

Adding and Removing Columns

dtypes and Type Conversion

describe and info

DataFrame Indexing Notation

Selection examples:

Handling Missing Data

apply and map

Sorting

Practical Example: Exploring a Dataset

Key Takeaways

  • Series is one-dimensional; DataFrame is two-dimensional – both are labeled.
  • Use loc for label-based access and iloc for position-based access.
  • describe() gives you instant statistical insight; info() shows structure and types.
  • Always check dtypes and convert types before analysis.
  • Boolean indexing is your primary filtering tool.
  • apply() is powerful but slower than vectorized operations – prefer vectorized when possible.

Need Expert Data Science Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement