我有一個Dataframe數據,里面有一列是wd的數據,我想把里面對應的數據做劃分,分為A~H級,自己寫了一段代碼,總是出錯,求大家指點指點。def func_wd(x):# 定義一個分級的函數for x in data['wd']:if x < 45.0:return 'A'elif x >= 45.0 and x < 90.0:return 'B'elif x >= 90.0 and x < 135.0:return 'C'elif x >= 135.0 and x < 180.0:return 'D'elif x >= 180.0 and x < 225.0:return 'E'elif x >= 225.0 and x < 270.0:return 'F'elif x >= 270.0 and x < 315.0:return 'G'else:return 'H'data['wd'] = data.applymap(func_wd)
為什么打印的數據都是H,整列都是H,大家指教一下
小唯快跑啊
2022-07-19 18:14:00