pandasNot Started
What is a DataFrame?
The core pandas data structure — a labeled 2D table
0%
Knowledge Debt detected
You can study this freely — but your score may plateau if these foundations have gaps. The Mastery badge requires them to be solid.
Explanation
A DataFrame is a 2D labeled data structure — think of it as a spreadsheet or SQL table inside Python.
Key concepts:
- Rows — each row is one observation (one record)
- Columns — each column is one variable/feature
- Index — the row labels (default: 0, 1, 2, …)
- dtype — each column has its own data type
python
import pandas as pd# Create from a dictionary df = pd.DataFrame({ 'name': ['Alice', 'Bob', 'Carol'], 'age': [25, 30, 35], 'salary': [50000, 65000, 80000] }) print(df) # name age salary # 0 Alice 25 50000 # 1 Bob 30 65000 # 2 Carol 35 80000 ```
Quick inspection:
df.shape→ (rows, columns)df.dtypes→ data type of each columndf.head(n)→ first n rows (default 5)df.info()→ summary including nullsdf.describe()→ statistics for numeric columns
Examples
Creating and inspecting a DataFrame
df.shape gives (rows, cols) like NumPy
import pandas as pd
df = pd.DataFrame({
'name': ['Alice', 'Bob', 'Carol'],
'age': [25, 30, 35],
'salary': [50000, 65000, 80000]
})
print(df.shape) # (3, 3)
print(df.dtypes)
# name object
# age int64
# salary int64
print(df.head(2))Next in pandas
Reading a CSV File