df.head(n)/df.tail(n): first or last rows.df.shape: (rows, columns).df.columns,df.dtypes,df.info()df.describe(): statistics for numeric columns.
Pandas DataFrames
Create and inspect tables.
✍️ 3 exercises + code challenge in this lessonKey Takeaways: Pandas DataFrames
Mastering Pandas DataFrames helps you write clean and reliable Pandas code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
Pandas DataFrames Code Example
Pandasimport pandas as pd
df = pd.DataFrame({
"product": ["Laptop", "Mouse", "Desk", "Pen"],
"price": [185000, 1500, 42000, 400],
"stock": [12, 150, 8, 300],
})
print(df.shape)
print(list(df.columns))
print(df.head(2))
print(df["price"].max())
Output
(4, 3) ['product', 'price', 'stock'] product price stock 0 Laptop 185000 12 1 Mouse 1500 150 185000
Free sign-in required · Google login available
Pandas DataFrames Practice Exercises
Check what you learned in “Pandas DataFrames”.
/ 3 solved
Fill in the blank
Show the first 3 rows.
df.(3)
✓ Correct!
Not quite. Try again.
Multiple choice
What does df.shape return?
✓ Correct!
Not quite. Try again.
Code challenge
Print the column names of df as a list.
Write the code in the live editor. Your answer is checked automatically.
✓ Solved
Free sign-in required · Google login available
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services