Complete the code to create 3 equal-width bins for the data.
import pandas as pd values = [1, 5, 8, 12, 15, 18] bins = pd.cut(values, [1]) print(bins)
Using pd.cut with the number 3 creates 3 equal-width bins.
Complete the code to create 4 bins with equal number of data points.
import pandas as pd values = [2, 4, 6, 8, 10, 12, 14, 16] bins = pd.qcut(values, [1]) print(bins)
Using pd.qcut with 4 creates 4 bins each having roughly equal number of points.
Fix the error in the code to create bins with custom edges.
import pandas as pd values = [3, 7, 11, 15, 19] bins = pd.cut(values, bins=[1]) print(bins)
The bins argument must be a list or array of bin edges, so use square brackets.
Fill both blanks to create bins and label them as 'Low', 'Medium', 'High'.
import pandas as pd values = [2, 5, 8, 11, 14] bins = pd.cut(values, [1], labels=[2]) print(bins)
Use bin edges [0, 6, 12, 18] and labels ['Low', 'Medium', 'High'] to categorize values.
Fill all three blanks to create quantile bins, assign labels, and include the lowest value.
import pandas as pd values = [1, 3, 5, 7, 9, 11] bins = pd.qcut(values, [1], labels=[2], [3]=True) print(bins)
Use 3 quantile bins with labels and include_lowest=True to cover the smallest value.
