🐼 What is Pandas
Pandas is Python's most popular tool for working with data. Think of it as giving Excel superpowers to Python - you can analyze, clean, and manipulate data with just a few lines of code instead of clicking through endless menus.
Let's see Pandas in action:
import pandas as pd
# Simple sales data
sales = {
'day': ['Mon', 'Tue', 'Wed'],
'amount': [100, 150, 120]
}
# Create a DataFrame
df = pd.DataFrame(sales)
print(df)
# Quick analysis
print(f"Total sales: {df['amount'].sum()}")
print(f"Average: {df['amount'].mean()}")
🔍 The Two Main Building Blocks
Pandas has two core data structures that you'll use for everything:
Understanding DataFrames
import pandas as pd
# DataFrame - Multiple columns
df = pd.DataFrame({
'name': ['Alice', 'Bob'],
'score': [85, 92]
})
print("DataFrame:")
print(df)
# Series - Single column
scores = df['score']
print("Series:")
print(scores)
print(f"Average: {scores.mean()}")
🚀 Why Pandas is a Game-Changer
Here's what makes Pandas special compared to other ways of working with data:
Task | Without Pandas | With Pandas |
---|---|---|
Load 1000-row CSV | Write complex file reading code | pd.read_csv('file.csv') |
Find average | Loop through data manually | df['column'].mean() |
Filter data | Write if statements and loops | df[df['sales'] > 100] |
Handle missing data | Check each value individually | df.fillna(0) or df.dropna() |
Group by category | Complex nested loops | df.groupby('category').sum() |
Sort data | Write sorting algorithms | df.sort_values('column') |
Simple Analysis Example
import pandas as pd
# Customer ratings
data = {
'customer': ['A', 'B', 'C', 'D'],
'rating': [5, 3, 4, 5]
}
df = pd.DataFrame(data)
print(df)
# Quick insights
print(f"Average rating: {df['rating'].mean()}")
print(f"High ratings: {len(df[df['rating'] >= 4])}")
🛠️ What Makes Pandas Powerful
Basic Operations
import pandas as pd
# Simple product data
products = pd.DataFrame({
'item': ['Laptop', 'Mouse', 'Keyboard'],
'price': [999, 25, 75],
'quantity': [2, 10, 5]
})
print(products)
# Add calculated column
products['total'] = products['price'] * products['quantity']
print(products)
# Filter data
expensive = products[products['price'] > 50]
print(expensive)
📊 When to Use Pandas
🎯 Key Takeaways
🚀 What's Next?
Now that you understand what Pandas is and why it's powerful, let's get it installed on your computer so you can start using it.
Continue to: Installing Pandas
Ready to turn data chaos into clear insights? Let's get Pandas set up! 📊✨
Was this helpful?
Track Your Learning Progress
Sign in to bookmark tutorials and keep track of your learning journey.
Your progress is saved automatically as you read.