Menu

Introduction to Pandas

Introduction to Pandas

Pandas is the main library you will use to work with tables of data. This topic introduces Series and DataFrames and shows you how to take a first look at any dataset.

a. What Is Pandas?

Pandas is the most popular Python library for working with table-like data. It makes it easy to load, clean, filter, and summarize data. Think of it as Excel with the power of code.

The name comes from "panel data", a term used in statistics. Pandas is built on top of NumPy, so it is fast and works well with other data tools.

You usually import it with the short name pd. From here on, almost every example in this handbook will use it.

import pandas as pd

b. Understanding Series

A Series is a single column of data with labels called an index. You can think of it as a list with names attached to each value.

marks = pd.Series([85, 90, 78], index=["Maths", "Science", "English"])
print(marks["Science"])

You can do math on a Series just like a NumPy array. You can also use methods like .mean(), .max(), and .sum().

A Series holds only one type of data at a time. When you pick one column from a table, Pandas gives it to you as a Series. This is why understanding it is important.

c. Understanding DataFrames

A DataFrame is a two-dimensional table with rows and columns. It is the main object you will work with in Pandas. Each column is a Series, and each column can have its own data type.

data = {
"name": ["Asha", "Ravi", "Meena"],
"age": [25, 30, 28],
"city": ["Chennai", "Delhi", "Mumbai"]
}
df = pd.DataFrame(data)
print(df)

You can create a DataFrame from a dictionary, a list of lists, or by reading a file. Most real projects start by loading a CSV or Excel file into a DataFrame.

You can access a column using df["age"] and add a new column with df["country"] = "India". The DataFrame is flexible and easy to update.

d. Exploring a DataFrame with head, info, and describe

When you load a new dataset, the first step is to look at it. The head() method shows the first five rows. This gives you a quick feel for the columns and values.

print(df.head())
df.info()
print(df.describe())

The info() method shows the column names, data types, and how many values are not missing. This helps you spot problems early, like a number column stored as text.

The describe() method gives summary statistics like mean, minimum, maximum, and quartiles for numeric columns. Also check df.shape to see the number of rows and columns. These simple checks save you from many mistakes later.


Data Analysis with Python Handbook

WR

Wesline Rinisha



Learn via Video Course

Data Analysis and Processing with Python using Pandas - Data Science Course Logo

Data Analysis and Processing with Python using Pandas - Data Science Course

5 hrs



Get in Touch For Details