Complete the code to create 3 equal-width bins for the data using cut().
import pandas as pd data = [5, 10, 15, 20, 25] bins = pd.cut(data, [1]) print(bins)
Using pd.cut with an integer creates that many equal-width bins.
Complete the code to create 4 bins with equal number of data points using qcut().
import pandas as pd data = [5, 10, 15, 20, 25, 30, 35, 40] bins = pd.[1](data, 4) print(bins)
qcut() creates bins with equal number of data points (quantiles).
Fix the error in the code to create bins with cut() using custom bin edges.
import pandas as pd values = [1, 2, 3, 4, 5] bins = pd.cut(values, bins=[1]) print(bins)
Custom bins must be a list of numbers defining bin edges.
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 if the word length is greater than 3.
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 word in words if len(word) [3] 4 } print(result)
The dictionary comprehension creates keys as uppercase words and values as their lengths, filtering words longer than 4 characters.