Organizing and analyzing data has never been this much fun! Think of Pandas as Excel superpowers for your Python code! 📊
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
df = pd.DataFrame({"Name": ["Tesla", "NagaMuthu"], "Score": [369, 630]})Simplifies working with tables of data!
Filter, sort, and transform data with ease!
Quickly create charts and visualizations!
Transform messy data into organized tables! ✨
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)| Name | Score | |
|---|---|---|
| 0 | Tesla | 369 |
| 1 | NagaMuthu | 630 |
| 2 | Sri | 500 |
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)
Think of a DataFrame as a whole spreadsheet, and a Series as just one column from that spreadsheet!
When you have data in files like CSV, Excel, or even databases, pandas helps you read it easily!
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!
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!
df.head()
Shows first 5 rows
df.info()
Column types & missing values
df.describe()
Statistical summary
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:
Pandas makes all of this super easy!
df = pd.DataFrame(data)
Create a DataFrame from a dictionary or array
pd.read_csv("file.csv")
Load data from CSV files
df[df["Score"] > 500]
Select rows based on conditions
df.plot(kind="bar")
Create bar charts, line plots, and more