DolphinDB中有bucket函数,函数的具体语法和参数可以参考https://docs.dolphindb.cn/zh/help/FunctionsandCommands/FunctionReferences/b/bucket.html?highlight=bucket
下面是一个DolphinDB和pandas进行数据分箱操作的对比示例:
DolphinDB中的示例:
bucket(9 23 54 36 46 12, 12:54, 2); [,0,,1,1,0]
bucket(9 23 54 36 46 12, 12:54, 2, 1); [0,1,3,2,2,1]
pandas中的示例:
import pandas as pd # 创建一维数组 data = [9, 23, 54, 36, 46, 12] # 定义箱体边界 bins = [12, 33, 54] # 使用pandas.cut进行数据分箱 bins_result = pd.cut(data, bins) # 打印结果 print(bins_result)