Reputation: 1
I have the following wine classification data:
country, price, colour
USA 10 white
italy 25 red
USA 75 rose
Germany 125 white
I have to add a new column in pandas
based on the information below:
New column Name is 'Affordability'
:
Cheap
if price < 50 or expensive
if price is >50 but Price <100 or very exp
if price >100
Upvotes: 0
Views: 155
Reputation: 96
You can use numpy.select
to add an extra column with conditions:
import numpy as np
condlst = [df['price_column'] < 50,
df['price_column'] < 100,
df['price_column'] >= 100]
choicelst = ['Cheap',
'Expensive',
'Very Expensive',]
df['Affordability'] = np.select(condlist, choicelst)
Please note:
More to read about np.select
here.
Upvotes: 1