Introduction to Pandas 📊
Last Updated: 26st August 2025
- Pandas is a Python library used for data analysis and manipulation.
- It provides two main data structures:
- Series → 1D labeled array (like an Excel column).
- DataFrame → 2D labeled table (like an Excel sheet).
- Pandas is built on top of NumPy and is widely used in Data Science, ML, and Data Analytics.
Hinglish Tip 🗣: Agar aapko Excel ya SQL ki tarah Python me data handle karna hai — rows/columns ke form me — toh Pandas sabse powerful library hai.
✏ Installing & Importing Pandas
# Install (only once in your environment)
pip install pandas
# Import
import pandas as pd
📊 Pandas Series (1D Data)
A Series is like a single column in Excel.
import pandas as pd
# Create a Series
s = pd.Series([10, 20, 30, 40], index=["a", "b", "c", "d"])
print(s)
print(type(s))
🎯 Accessing Series Data
print(s["a"]) # by label → 10
print(s[0]) # by index → 10
print(s.values) # only values → [10 20 30 40]
print(s.index) # only index → Index(['a','b','c','d'], dtype='object')
🧮 Operations on Series
print(s + 5) # Add 5 to all values
print(s.mean()) # Mean → 25.0
print(s.max()) # Max → 40
print(s.min()) # Min → 10
print(s.sum()) # Sum → 100
print(s.count()) # Count → 4
print(s.unique()) # Unique values → [10 20 30 40]
print(s.nunique()) # Unique values count → 4
print(s.value_counts()) # Value counts → a 1, b 1, c 1, d 1
print(s.sort_values()) # Sort values → a 10, b 20, c 30, d 40
Hinglish Tip 🗣: Series ko hum ek list + dictionary dono ka mix samajh sakte hai. Isme values bhi hoti hain aur unke labels (index) bh
💡 Quick Practice
- Create a Series of 5 fruits with their quantities.
- Access the 2nd fruit using both label and index.
- Find the mean and maximum quantity.