🧱 Pandas Basics – Core Operations & Data Handling Fundamentals
🧲 Introduction – Understand the Building Blocks of Pandas
Before diving into advanced data analysis, it’s essential to master basic Pandas operations. These include creating Series and DataFrames, accessing and modifying data, filtering, sorting, and summarizing information.
🎯 In this guide, you’ll learn:
- How to create and inspect Pandas objects
- Basic data access methods using labels and conditions
- How to modify, filter, and sort your data
- Methods to summarize and explore datasets quickly
📦 1. Create Series and DataFrames
import pandas as pd
# Create a Series
series = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
# Create a DataFrame
data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = pd.DataFrame(data)
✅ A Series is a one-dimensional labeled array
✅ A DataFrame is a two-dimensional table-like structure
🔍 2. Inspecting Data
| Method | Purpose | 
|---|---|
| df.head() | View first 5 rows | 
| df.tail() | View last 5 rows | 
| df.shape | Get number of rows and columns | 
| df.info() | Summary of columns, non-null values | 
| df.describe() | Statistical summary for numeric columns | 
| df.columns | List of column names | 
| df.index | Row index info | 
🧭 3. Accessing Data
👉 Access by Column Name
print(df['Name'])   # Single column
print(df[['Name', 'Age']])  # Multiple columns
👉 Access by Row Index
print(df.iloc[0])   # By position
print(df.loc[0])    # By label (index)
🔁 4. Filtering Rows with Conditions
# Age > 25
filtered = df[df['Age'] > 25]
print(filtered)
👉 Output:
  Name  Age
1  Bob   30
✅ Use boolean expressions to filter rows
🛠️ 5. Modifying Data
# Add new column
df['Score'] = [90, 85]
# Modify existing value
df.loc[0, 'Age'] = 26
✅ You can assign new columns or update individual cells directly
🔃 6. Sorting Data
# Sort by column
df.sort_values(by='Age', ascending=False)
✅ Use sort_values() to order rows based on any column
🔄 7. Handling Missing Data
df.isnull()        # Detect missing
df.dropna()        # Remove rows with missing values
df.fillna(0)       # Replace missing with 0
✅ Pandas provides rich functions to clean missing or null data efficiently
📊 8. Basic Aggregation
df['Age'].mean()       # Average age
df['Age'].sum()        # Total age
df['Age'].max()        # Oldest person
✅ Use aggregation methods like sum(), mean(), max(), min(), count() on Series or DataFrames
📌 Summary – Recap & Next Steps
These basic Pandas operations form the foundation of all advanced data analysis tasks. With just a few lines of code, you can filter, transform, and inspect structured data efficiently.
🔍 Key Takeaways:
- Use Series for 1D data, DataFrames for 2D tabular data
- Access and filter data using [],.loc[], and.iloc[]
- Clean, sort, and summarize data using built-in functions
- Aggregation and transformation are simple and expressive
⚙️ Real-world relevance: These basics enable analysts and data scientists to prepare datasets for modeling, dashboarding, or reporting.
❓ FAQs – Pandas Basics
❓ What’s the difference between .loc[] and .iloc[]?
✅ .loc[] accesses by label (index name), .iloc[] accesses by position (row number)
❓ Can I add new columns on the fly?
✅ Yes, just assign a list/Series to df['NewColumn']
❓ How do I check for missing values?
Use df.isnull() to return a Boolean mask of missing values
❓ Is it necessary to reset index after filtering?
Not required, but for clean sequential indexing use:
df.reset_index(drop=True)
❓ Are DataFrames mutable?
✅ Yes, you can modify values, rows, and columns directly
Share Now :
