Thuta Learning
IntermediateProgrammingbeginner

Pandas Tutorial (Enhanced)

Relax. We'll talk through this in plain words — no textbook voice.

🐼 Lesson 49: Pandas Tutorial (Data Analysis Basics)

1. What is Pandas?

In short → Pandas is a widely-used Python library for data analysis and data manipulation. It can easily read data formats like CSV, Excel, SQL database, and JSON, then filter, group, and aggregate them.

English → Pandas is a Python library for data analysis and manipulation, supporting multiple data formats and powerful operations.

2. Core Data Structures

  • Series → 1D labeled array
  • DataFrame → 2D table (rows + columns)

3. Summary

✅ Pandas = data analysis library

✅ Core structures → Series, DataFrame

✅ Read/Write → CSV, Excel, JSON, SQL

✅ Inspect, filter, group, aggregate → data manipulation

python
# ===== 1. Pandas Installation & Import =====
# pip install pandas
import pandas as pd

# ===== 2. Creating Series & DataFrame =====
print("===== Creating Data Structures =====")

# Series
s = pd.Series([10, 20, 30, 40])
print(f"Series:\n{s}")

# DataFrame
data = {"Name": ["Sai", "Aye", "Mya"], "Age": [25, 22, 30]}
df = pd.DataFrame(data)
print(f"\nDataFrame:\n{df}")

# ===== 3. Reading & Writing Data =====
print(f"\n===== File Operations =====")
print("# Read CSV: df = pd.read_csv('data.csv')")
print("# Read Excel: df = pd.read_excel('data.xlsx')")
print("# Write CSV: df.to_csv('output.csv', index=False)")

# ===== 4. Inspecting Data =====
print(f"\n===== Data Inspection =====")
print(f"Head (first 2 rows):\n{df.head(2)}")
print(f"\nInfo:\n{df.info()}")
print(f"\nDescribe:\n{df.describe()}")

# ===== 5. Selecting Data =====
print(f"\n===== Selecting Data =====")
print(f"Column 'Name':\n{df['Name']}")
print(f"\nColumns 'Name' and 'Age':\n{df[['Name', 'Age']]}")
print(f"\nFirst row:\n{df.iloc[0]}")

# ===== 6. Filtering Data =====
print(f"\n===== Filtering =====")
filtered = df[df["Age"] > 23]
print(f"Age > 23:\n{filtered}")

# ===== 7. Grouping & Aggregation =====
print(f"\n===== Aggregation =====")
print(f"Mean Age: {df['Age'].mean()}")
print(f"Max Age: {df['Age'].max()}")
You should see
===== Creating Data Structures ===== Series: 0 10 1 20 2 30 3 40 dtype: int64 DataFrame: Name Age 0 Sai 25 1 Aye 22 2 Mya 30 ===== File Operations ===== # Read CSV: df = pd.read_csv('data.csv') # Read Excel: df = pd.read_excel('data.xlsx') # Write CSV: df.to_csv('output.csv', index=False) ===== Data Inspection ===== Head (first 2 rows): Name Age 0 Sai 25 1 Aye 22 Info: RangeIndex: 3 entries, 0 to 2 Data columns (total 2 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Name 3 non-null object 1 Age 3 non-null int64 dtypes: int64(1), object(1) memory usage: 176.0+ bytes None Describe: Age count 3.000000 mean 25.666667 std 4.163332 min 22.000000 25% 23.500000 50% 25.000000 75% 27.500000 max 30.000000 ===== Selecting Data ===== Column 'Name': 0 Sai 1 Aye 2 Mya Name: Name, dtype: object Columns 'Name' and 'Age': Name Age 0 Sai 25 1 Aye 22 2 Mya 30 First row: Name Sai Age 25 Name: 0, dtype: object ===== Filtering ===== Age > 23: Name Age 0 Sai 25 2 Mya 30 ===== Aggregation ===== Mean Age: 25.666666666666668 Max Age: 30
Pandas Tutorial (Enhanced) | Thuta Learning