pandas basics: Series and DataFrames
Python · 15 questions
Short notes
Key idea
pandas gives you the DataFrame: a table with named columns and a row index. You load data, look at it, and select columns before doing anything clever.
Syntax
import pandas as pd
df = pd.read_csv("orders.csv")
df.head() # first 5 rows
df.shape # (rows, columns)
df.info() # column types and non-null counts
df.describe() # numeric summary
df["amount"] # one column → Series
df[["city", "amount"]] # several columns → DataFrame
df["amount"].mean()
df["city"].value_counts()
Example
df = pd.read_csv("orders.csv")
print(df.shape)
print(df["city"].value_counts().head(3))
print(round(df["amount"].mean(), 2))
Three lines tell you how big the data is, where orders come from and the average order.
Traps
- One bracket gives a Series, two brackets a DataFrame.
- Numbers read as text (because of a stray "N/A" or ₹ sign) show as
objectininfo(); fix them before maths. head()shows a sample, not the whole story. Checkshapeandinfo()too.- Most methods return a new DataFrame; assign the result or nothing changes.
Want the full lesson with step-by-step examples, a project and a certificate? Python course, ₹120 →
- Question 1easy
How do you get the number of rows and columns of a DataFrame
df? - Question 2easy
What does
customers["city"]return? - Question 3easy
What does this print?
print(orders.shape[0])
- Question 4medium
2 orders have no payment method. What does this print?
print(orders["payment_method"].value_counts().sum())
- Question 5medium
What does this print?
print(customers["city"].nunique())
pandas basics: Series and DataFrames
pandas basics: Series and DataFrames
pandas basics: Series and DataFrames
pandas basics: Series and DataFrames
pandas basics: Series and DataFrames
10 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.