Challenge - 5 Problems
Histogram Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of histogram bin counts
What is the output of the following code that plots a histogram and returns the counts of values in each bin?
Pandas
import pandas as pd import matplotlib.pyplot as plt data = pd.Series([1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) counts, bins, patches = plt.hist(data, bins=4, edgecolor='black') plt.close() print(counts)
Attempts:
2 left
💡 Hint
Count how many values fall into each bin range when bins=4.
✗ Incorrect
The data has 1 value in the first bin (1), 2 values in the second bin (2,2), 3 values in the third bin (3,3,3), and 4 values in the last bin (4,4,4,4).
❓ data_output
intermediate1:30remaining
Number of bins in histogram
How many bins will the histogram have in this code snippet?
Pandas
import pandas as pd import matplotlib.pyplot as plt data = pd.Series([5, 7, 8, 5, 6, 7, 8, 9, 10, 11]) plt.hist(data, bins=5) plt.close()
Attempts:
2 left
💡 Hint
The bins parameter sets the number of bins directly.
✗ Incorrect
The bins parameter is set to 5, so the histogram will have exactly 5 bins.
❓ visualization
advanced2:30remaining
Identify the histogram shape
Given this data and histogram code, what shape does the histogram plot show?
Pandas
import pandas as pd import matplotlib.pyplot as plt import numpy as np data = pd.Series(np.concatenate([np.random.normal(0, 1, 500), np.random.normal(5, 1, 500)])) plt.hist(data, bins=30, edgecolor='black') plt.close()
Attempts:
2 left
💡 Hint
The data is combined from two normal distributions centered at different points.
✗ Incorrect
The data combines two normal distributions centered at 0 and 5, so the histogram shows two peaks, making it bimodal.
🔧 Debug
advanced2:00remaining
Error in histogram plotting code
What error does this code raise when trying to plot a histogram?
Pandas
import pandas as pd import matplotlib.pyplot as plt data = pd.Series(['a', 'b', 'c', 'a', 'b']) plt.hist(data) plt.close()
Attempts:
2 left
💡 Hint
Histograms require numeric data to bin values.
✗ Incorrect
Matplotlib histogram expects numeric data to create bins. Strings cannot be converted to float for binning, causing a TypeError.
🚀 Application
expert3:00remaining
Choosing bin size for histogram analysis
You have a dataset of 10,000 numeric values with a wide range. You want to plot a histogram to analyze the distribution clearly. Which bin size choice is best to balance detail and readability?
Attempts:
2 left
💡 Hint
Too few bins hide details; too many bins create noise.
✗ Incorrect
50 bins provide enough detail to see distribution shape without overwhelming noise or empty bins, suitable for 10,000 data points.