A. The parameter 'xlabel' is not valid in df.hist()
B. The 'bins' parameter must be a list, not an integer
C. The column name must be passed as a list ['height']
D. The DataFrame is missing a required index
Solution
Step 1: Check df.hist() parameters
df.hist() does not accept 'xlabel' parameter directly.
Step 2: Identify correct way to label axes
Labels should be set using matplotlib functions after plotting, not as df.hist() arguments.
Final Answer:
The parameter 'xlabel' is not valid in df.hist() -> Option A
Quick Check:
Use plt.xlabel() to label axes, not df.hist() args [OK]
Hint: Use plt.xlabel() for labels, not df.hist() params [OK]
Common Mistakes:
Passing axis labels as df.hist() arguments
Thinking bins must be a list
Assuming column name must be a list
5. You have a DataFrame df with a 'salary' column containing values from 2000 to 10000. You want to create a histogram with 4 bins and label the x-axis as 'Salary Range'. Which code correctly achieves this?
hard
A. ax = df['salary'].hist(bins=4)
ax.xlabel('Salary Range')
B. df.hist('salary', bins=4, xlabel='Salary Range')
C. df['salary'].plot.hist(bins=4, xlabel='Salary Range')
D. df['salary'].hist(bins=4)
plt.xlabel('Salary Range')
Solution
Step 1: Plot histogram with bins=4
Use df['salary'].hist(bins=4) to create histogram with 4 bins.
Step 2: Label x-axis correctly
Use matplotlib's plt.xlabel('Salary Range') after plotting to set label.
Final Answer:
df['salary'].hist(bins=4)
plt.xlabel('Salary Range') -> Option D
Quick Check:
Use plt.xlabel() after hist() for axis label [OK]
Hint: Set labels with plt.xlabel() after plotting histogram [OK]
Common Mistakes:
Passing xlabel directly to hist()
Using plot.hist() with xlabel param
Not labeling axes at all
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.