Given a DataFrame df with some missing values, what does the following code output?
import pandas as pd import numpy as np data = {'A': [1, 2, np.nan, 4], 'B': [np.nan, 2, 3, 4]} df = pd.DataFrame(data) missing_counts = df.isnull().sum() print(missing_counts)
Use isnull() to find missing values, then sum() counts them per column.
The isnull() method marks missing values as True. Summing counts Trues per column. Column 'A' has 1 missing, 'B' has 1 missing.
Consider this DataFrame df. After filtering rows where column 'Age' is greater than 30, what is the shape of the resulting DataFrame?
import pandas as pd data = {'Name': ['Alice', 'Bob', 'Charlie', 'David'], 'Age': [25, 35, 30, 40]} df = pd.DataFrame(data) filtered_df = df[df['Age'] > 30] print(filtered_df.shape)
Count rows where 'Age' > 30.
Only Bob (35) and David (40) have Age > 30, so 2 rows remain with 2 columns.
You have a DataFrame df with a 'Salary' column. Which code snippet produces a histogram of 'Salary' with 10 bins?
All these methods create histograms with 10 bins.
Each option uses pandas plotting to create a histogram of 'Salary' with 10 bins. All are valid and produce similar plots.
What error occurs when running this code?
import pandas as pd data = {'A': [1, 2, 3], 'B': [4, 5, 6]} df = pd.DataFrame(data) mean_val = df['C'].mean()
Check if column 'C' exists in the DataFrame.
Accessing a non-existent column 'C' raises a KeyError in pandas.
Given a DataFrame df with numeric columns, which code correctly computes the correlation matrix?
import pandas as pd data = {'X': [1, 2, 3, 4], 'Y': [4, 3, 2, 1], 'Z': [10, 20, 30, 40]} df = pd.DataFrame(data)
Use the pandas method for correlation matrix.
The correct pandas method is corr(). Other options are invalid or do not exist.