用熊猫修改列的问题

时间:2020-09-13 09:48:16

标签: python-3.x pandas pandas-groupby

我有一个数据框,我想为其创建一个名为result的新列,如果“ mean”列的值小于10,则该列应为“ refuse”,否则拒绝列的值应为“ Admitted”

[this is the image of my dataframe I want to create a "result" column that takes the value admitted and refuse 1

2 个答案:

答案 0 :(得分:1)

您在这里:

import numpy as np
data['new_col'] = np.where(data['mean'] < 10, 'refuse', 'Admitted')

答案 1 :(得分:0)

data.loc[(data['mean'] < 10), 'result'] = 'Refuse'
data.loc[(data['mean'] >= 10), 'result'] = 'Admitted'