1 回答

TA貢獻1797條經(jīng)驗 獲得超6個贊
沒有提供樣本數(shù)據(jù)。測試邊緣情況似乎都很好。我正在使用熊貓 1.1
df = pd.DataFrame({"Number of Locations":[32,33,34,35,36,np.inf,np.nan,34.0001]})
bins = [1, 10, 20, 34, np.Inf]
labels = ['1-10', '11-20', '21-34', '35 -Inf']
df['binned'] = pd.cut(df['Number of Locations'], bins=bins, labels=labels, include_lowest=True)
print(df.to_string())
輸出
Number of Locations binned
0 32.0000 21-34
1 33.0000 21-34
2 34.0000 21-34
3 35.0000 35 -Inf
4 36.0000 35 -Inf
5 inf 35 -Inf
6 NaN NaN
7 34.0001 35 -Inf
添加回答
舉報