Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 64 ยท Getting Started

What Is pandas?

Learn what pandas is, what Series and DataFrame objects are, when to choose pandas over NumPy or SQL, and how to run every example in your browser.

pandas is the Python library for working with tables of data. If you have ever used a spreadsheet, you already know the idea: rows, columns, headers, formulas, filters, totals. pandas gives you all of that as code. You can load a file with a million rows, clean it, group it, join it with another table and chart the result in a few readable lines. Because it is code, your analysis is repeatable. Run it again tomorrow on fresh data and you get the same steps and the same kind of answer.

The name comes from "panel data", an economics term for observations of many subjects over time. Today pandas is the standard tool for data cleaning, exploration and reporting in Python. It sits underneath much of the Python data stack: plotting libraries, machine-learning libraries and notebooks all accept pandas objects.

This course teaches pandas 3, the current major version. A few behaviors changed compared with older tutorials you may find online, and we will point them out where they matter.

The two objects you need to know

Almost everything in pandas revolves around two types:

  • A Series is one column of data: a sequence of values with a label for each value (the index) and a single data type.
  • A DataFrame is a table: several Series that share the same index. Each column has its own data type.
flowchart LR
    S1["Series: price"] --> DF
    S2["Series: quantity"] --> DF
    S3["Series: city"] --> DF
    DF["DataFrame<br/>(columns sharing one index)"]

A DataFrame is a collection of Series that share the same row labels.

Here is the smallest useful program. It imports pandas under its conventional short name pd, builds a DataFrame from a dictionary and prints it:

Python Your first DataFrame

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Each key of the dictionary became a column. The numbers on the left (0 to 3) are the index, which pandas created for you. Everything you do from here on is some combination of looking at, selecting, changing and combining tables like this one.

Note: the convention import pandas as pd is used in nearly every pandas book, answer and project. Follow it, so your code looks familiar to every other pandas user.

Doing something useful in three lines

A DataFrame is more than a way to print data. Operations apply to a whole column at once, with no loop. Let's compute the revenue for each product and find the total:

Python Revenue per product

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The line orders["price"] * orders["quantity"] multiplies the two columns element by element. This style is called vectorized computation, and it is the heart of fast pandas code. You will meet it again in Vectorised Operations.

Checking your version

Because pandas 3 changed some defaults, it helps to know which version you are running. Normally you would print pd.__version__. In the example below we only check the major number, so the output stays the same whichever 3.x release the page uses:

Python Checking the version

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The dtype str is one of the pandas 3 changes: text columns now have their own string type, where older versions stored them as generic Python objects. Another is Copy-on-Write: changing a table you derived from another table never changes the original by accident. Both topics get their own lessons later (Data Types and Conversion and Creating and Changing Columns).

pandas, NumPy or SQL?

pandas is not the only way to work with numbers and tables. Here is how to choose:

Tool Best at Typical shape of data
NumPy Fast math on grids of one numeric type Matrices, images, simulations
pandas Mixed, labeled, messy tabular data in memory Files, exports, reports, analysis
SQL Querying data that lives in a database Very large, shared, long-lived tables

NumPy arrays have no column names and hold one type, which is perfect for linear algebra but awkward for "the average price per city". pandas is built on NumPy, so you get its speed and add labels, mixed types, missing-value handling, dates, grouping and joins. You can learn more about the array foundation in the Python NumPy lesson and the Python pandas overview.

SQL and pandas overlap a lot: SELECT, WHERE, GROUP BY and JOIN all have pandas equivalents, and you will learn them here. The practical rule is that SQL is for getting the right rows out of a database, and pandas is for what you do with them afterwards. Many real projects use both.

flowchart LR
    A["Files, APIs, databases"] --> B["pandas<br/>load, clean, reshape"]
    B --> C["Analysis and statistics"]
    B --> D["Charts and reports"]
    B --> E["Machine-learning input"]

pandas sits in the middle of most data workflows: data goes in raw and comes out ready to use.

How the examples in this course run

Every code block with a Run button executes inside your browser using Pyodide, a build of Python for the web. Nothing is sent to a server, and pandas, NumPy and matplotlib are already available, so you can edit any example and run it again. A few consequences are worth knowing:

  • There is no real file system. We read data from strings (using io.StringIO) or generate it in code.
  • There is no internet, so examples never download data.
  • Each run starts fresh, so you cannot rely on variables from a previous example.
  • Programs stop after about 30 seconds.

When something cannot run in the browser, such as reading Excel files, we show it as a plain read-only code block and say so. On your own computer, install pandas with pip install pandas and everything works the same way.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is a DataFrame?

    A DataFrame is a table of labeled columns. Each column is a Series, and different columns can have different data types.
  2. 2. What does import pandas as pd do?

    The import loads the already-installed library, and "as pd" is just an alias. Nearly all pandas code uses this exact spelling.
  3. 3. Which task is pandas best suited for?

    pandas excels at in-memory analysis of labeled, mixed, imperfect tabular data. It is not a database server or a graphics engine.
  4. 4. Why do the examples in this course not read files from your disk?

    The in-browser Python has no real file system. pandas reads files fine on your own computer; here we use io.StringIO and generated data instead.

Summary

  • pandas is Python's main library for tabular data: load, clean, transform, combine, summarize and plot.
  • A Series is one labeled column; a DataFrame is a table of Series sharing one index.
  • Import it as import pandas as pd; this course uses pandas 3 (string dtype, Copy-on-Write).
  • Operations work on whole columns at once (vectorized), without Python loops.
  • Choose NumPy for numeric grids, pandas for labeled analysis in memory, SQL for querying databases.
  • Examples run in your browser; data comes from strings and generated values.

Next: Series, the one-dimensional building block of every DataFrame.