下記の設問に対する答えとして相応しものを選択肢から選び、次のコードの空欄(##########)を埋めてください.
Q1:各ビンに含まれる要素の項数が均等になるように、変数 df の “Weight” 列を 5 ビン詰めしてください.また、ビン名には bin_labels を指定してください.
Q2:Q1 で得られた Category の各ビンごとのデータの個数をカウントしてください.
import pandas as pd
import numpy as np
df = pd.DataFrame({“Height” : np.arange(155, 185, 3),
“Weight” : np.arange(45, 85, 4),
“Sex” : [“Female”, “Male”, “Male”, “Female”, “Female”, “FeMale”, “Female”, “Male”, “Male”, “Male”],
“School Year” : [1, 1, 2, 4, 3, 4, 5, 5, 6, 6]})
measure_weight = [40, 50, 60, 70, 80, 90]
bin_labels = [“Thin”, “Near Thin”, “Mean”, “Near Fat”, “Fat”]
cutting_weight = ##########
print(##########)
[Q1 選択肢]
1. df.Weight.cut(measure_weight, labels=bin_labels)
2. df.Weight.qcut(df.Weight, 5, labels=bin_labels)
3. pd.cut(df.Weight, measure_weight, labels=bin_labels)
4. pd.qcut(df.Weight, 5, labels=bin_labels)
[Q2 選択肢]
1. cutting_weight.sum()
2. pd.sum(cutting_weight)
3. cutting_weight.value_counts()
4. pd.value_counts(cutting_weight)