Choose the best reason why DataFrame is central to data analysis tasks.
Think about how you work with tables in real life, like spreadsheets.
DataFrames organize data in rows and columns, similar to spreadsheets, which makes data easy to access, filter, and analyze.
Given the code below, what is the shape (rows, columns) of the resulting DataFrame?
import pandas as pd data = {'Name': ['Anna', 'Bob', 'Cara'], 'Age': [28, 34, 29], 'City': ['NY', 'LA', 'SF']} df = pd.DataFrame(data) print(df.shape)
Count the number of rows and columns in the data dictionary.
The DataFrame has 3 rows (one for each person) and 3 columns (Name, Age, City).
What rows remain after filtering the DataFrame for Age > 30?
import pandas as pd data = {'Name': ['Anna', 'Bob', 'Cara', 'Dan'], 'Age': [28, 34, 29, 40]} df = pd.DataFrame(data) filtered = df[df['Age'] > 30] print(filtered)
Look for rows where Age is greater than 30.
Only Bob (34) and Dan (40) have Age values greater than 30, so only their rows remain.
Given a DataFrame with ages, which plot type best visualizes the age distribution?
import pandas as pd import matplotlib.pyplot as plt data = {'Age': [22, 25, 29, 22, 30, 25, 28, 29, 30, 22]} df = pd.DataFrame(data) # Assume the plot is created here
Think about how to show how many times each age appears.
A histogram groups ages into bins and shows how many values fall into each, making it ideal for distribution.
What error occurs when running this code?
import pandas as pd data = {'Name': ['Anna', 'Bob'], 'Age': [28, 34]} df = pd.DataFrame(data) # Attempt to access a non-existent column print(df['Salary'])
Check what happens when you try to access a column that is not in the DataFrame.
Accessing a column that does not exist in a DataFrame raises a KeyError.