ValueError: labels must be unique if ordered=True; pass ordered=False for duplicate labels
bins_2 = np.arange(11.25, 371.25, 22.5)
bins_2 = np.insert(bins_2, 0, 0)
bins_2 = np.append(bins_2, 360)
labels_2 = np.arange(1, 17)
labels_2 = np.append(labels_2, 1)
bins_2
Out[5]:
array([ 0. , 11.25, 33.75, 56.25, 78.75, 101.25, 123.75, 146.25,
168.75, 191.25, 213.75, 236.25, 258.75, 281.25, 303.75, 326.25,
348.75, 360. ])
labels_2
labels_2
Out[6]: array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1])
pd.cut(df_10min_1[spectral_wind_profile.wd_hub], bins=bins_2, labels=labels_2,
include_lowest=True)
报错:ValueError: labels must be unique if ordered=True; pass ordered=False for duplicate labels
。
提示信息翻译:当 ordered=True
的时候,labels的值必须是唯一的,而我的labels_2里面有重复值,
解决办法:
a = pd.cut(df_10min_1[spectral_wind_profile.wd_hub], bins=bins_2, labels=labels_2,
include_lowest=True, ordered=False)