【发布时间】:2018-11-07 19:34:26
【问题描述】:
我有一个如下所示的数据框,我想创建 4 列来计算准确度分布
Company Error_Rate
A 9
B 10
c 20
GK 17
GK 18
GK 30
GK 35
GK 25
GK 32
GK 40
GK 50
MB 60
MB 70
MB 70
我希望有这样一张桌子
Company Error_Rate Above 90% 80% - 90% 65% - 80% Below 65%
A 9 1 0 0 0
B 10 1 0 0 0
c 20 0 1 0 0
GK 17 0 1 0 0
GK 18 0 1 0 0
GK 30 0 0 1 0
GK 35 0 0 1 0
GK 40 0 0 0 1
我试过了
df['Above 90%'] = np.where(df['Error_Rate']<=10,1,0)
df['80% - 90%'] = np.where(df['Error_Rate'] <= 20,(np.where(df['Error_Rate'] > 10, 1, 0)),0)
df['65% - 80%'] = np.where(df['Error_Rate'] <= 35,(np.where(df['Error_Rate'] > 20, 1, 0)),0)
df['Below 65%'] = np.where(df['Error_Rate']>35,1,0)
它没有给我想要的结果。我是不是哪里出错了?
【问题讨论】:
标签: python pandas dataframe conditional