Pandas is widely used for data analysis. Which reason best explains why Pandas is preferred for handling tabular data?
Think about what makes working with rows and columns easier in Pandas.
Pandas offers DataFrame and Series, which are like tables and columns. These structures make it simple to select, filter, and transform data quickly.
What is the output of this code snippet?
import pandas as pd df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [5, 6, 7, 8]}) filtered = df[df['A'] > 2] print(filtered)
Look at the condition used to filter rows.
The code filters rows where column 'A' has values greater than 2, so only rows with A=3 and A=4 remain.
Given the DataFrame below, what is the result of grouping by 'Category' and calculating the sum of 'Value'?
import pandas as pd df = pd.DataFrame({'Category': ['A', 'B', 'A', 'B', 'C'], 'Value': [10, 20, 30, 40, 50]}) grouped = df.groupby('Category').sum() print(grouped)
Sum the 'Value' for each unique 'Category'.
Category 'A' has values 10 and 30 (sum 40), 'B' has 20 and 40 (sum 60), 'C' has 50.
What error does this code produce?
import pandas as pd df = pd.DataFrame({'X': [1, 2, 3], 'Y': [4, 5, 6]}) result = df['Z'] + 1 print(result)
Check if the column 'Z' exists in the DataFrame.
The DataFrame has columns 'X' and 'Y' only. Accessing 'Z' raises a KeyError.
You have two DataFrames: one with sales data and one with product info. Which Pandas operation correctly merges these and calculates total sales per product?
import pandas as pd sales = pd.DataFrame({'ProductID': [1, 2, 1, 3], 'Quantity': [5, 3, 2, 4]}) products = pd.DataFrame({'ProductID': [1, 2, 3], 'Name': ['Pen', 'Pencil', 'Eraser']})
Think about joining on a common column and then grouping by product name.
Option B merges on 'ProductID', then groups by 'Name' to sum quantities, giving total sales per product.