Stephy_IA
Stephy_IA

Reputation: 31

problem of modifying a column with pandas

I have a dataframe for which I want to create a new column called result which should take the value "refuse" if the value of the column "mean" is less than 10 otherwise the refuse column should take the value "Admitted".

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

Upvotes: 0

Views: 53

Answers (2)

Arkadiusz
Arkadiusz

Reputation: 1875

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

Upvotes: 0

gtomer
gtomer

Reputation: 6574

Here you go:

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

Upvotes: 1

Related Questions