狐的传说
使用pd.cut:df['class'] = pd.cut(df.occurrence, bins=[0,1,5,np.inf], labels=['Unique','Medium','High'])例如:df = pd.DataFrame({'occurrence':np.random.randint(0,10,10)})>>> df occurrence0 51 12 63 74 55 76 77 18 29 7df['class'] = pd.cut(df.occurrence, bins=[0,1,5,np.inf], labels=['Unique','Medium','High'])>>> df occurrence class0 5 Medium1 1 Unique2 6 High3 7 High4 5 Medium5 7 High6 7 High7 1 Unique8 2 Medium9 7 High