Pandas: Your Data Superpower! 🐼

Organizing and analyzing data has never been this much fun! Think of Pandas as Excel superpowers for your Python code! 📊

What Is Pandas?
The ultimate data toolbox!

Pandas is a super powerful Python library that helps you work with data tables. It's like having a spreadsheet program (like Excel) inside your Python code, but with super powers!

To use pandas in your code: import pandas as pd

Why use Pandas?

📊 Easy to Use

Simplifies working with tables of data!

🚀 Powerful Tools

Filter, sort, and transform data with ease!

📈 Makes Graphs

Quickly create charts and visualizations!

The Pandas Magic
CSVExcelJSONpandasNameScoreClassTesla369ScienceNagaMuthu630MathSri500Science

Transform messy data into organized tables! ✨

Main Pandas Superpowers
The key building blocks

DataFrame

A 2D table with rows and columns - like a spreadsheet or database table

import pandas as pd

data = {
  "Name": ["Tesla", "NagaMuthu", "Sri"],
  "Score": [369, 630, 500]
}

df = pd.DataFrame(data)
print(df)
NameScore
0Tesla369
1NagaMuthu630
2Sri500

Series

A 1D array with labels - like a single column in a spreadsheet

import pandas as pd

scores = pd.Series([369, 630, 500],
  index=["Tesla", "NagaMuthu", "Sri"])

print(scores)
Tesla       369
NagaMuthu   630
Sri        500
dtype: int64

Think of a DataFrame as a whole spreadsheet, and a Series as just one column from that spreadsheet!

Pandas in Action: Step by Step
Let's see it work!

Step 1: Loading Data

When you have data in files like CSV, Excel, or even databases, pandas helps you read it easily!

Reading a CSV File:

import pandas as pd

# Read data from CSV file
df = pd.read_csv("students.csv")

# Display first 5 rows
print(df.head())

Real-world example: Loading test scores of students from a CSV file the teacher saved from their gradebook!

Reading an Excel File:

import pandas as pd

# Read data from Excel file
df = pd.read_excel("sales.xlsx",
  sheet_name="January")

# Check data info
print(df.info())

Real-world example: Loading monthly sales data from an Excel spreadsheet that the store manager updates!

Checking Your Data:

df.head()

Shows first 5 rows

df.info()

Column types & missing values

df.describe()

Statistical summary

Real-World Example: Student Analysis
Let's see everything in action!

The School Dashboard Project

Imagine you're helping the school principal create a dashboard to understand student performance better. You have a file with test scores from different classes, and you need to:

  • Find which classes are performing best
  • Identify students who might need extra help
  • See if attendance affects test scores
  • Create charts for the principal's meeting

Pandas makes all of this super easy!

Cheat Sheet! 📝

Creating DataFrames

df = pd.DataFrame(data)

Create a DataFrame from a dictionary or array

Reading Files

pd.read_csv("file.csv")

Load data from CSV files

Filtering Data

df[df["Score"] > 500]

Select rows based on conditions

Creating Charts

df.plot(kind="bar")

Create bar charts, line plots, and more