Complete the code to create 3 equal-width bins from the data using cut().
import pandas as pd values = [5, 10, 15, 20, 25] bins = pd.cut(values, [1]) print(bins)
The bins parameter in pd.cut() expects an integer for the number of equal-width bins.
Complete the code to create 4 quantile-based bins using qcut().
import pandas as pd values = [1, 2, 3, 4, 5, 6, 7, 8] quantile_bins = pd.qcut(values, [1]) print(quantile_bins)
The qcut() function divides data into quantiles. Passing 4 creates quartiles.
Fix the error in the code to label bins with custom names using cut().
import pandas as pd values = [10, 20, 30, 40, 50] labels = ['Low', 'Medium', 'High'] binned = pd.cut(values, bins=3, labels=[1]) print(binned)
The labels parameter expects a list of labels matching the number of bins.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension maps each word to its length, filtering words longer than 3 characters.
Fill all three blanks to create a dictionary of uppercase words with their lengths for words longer than 4 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] result = {{ [1]: [2] for w in words if len(w) [3] 4 }} print(result)
This dictionary comprehension creates keys as uppercase words and values as their lengths, filtering words longer than 4 characters.