I have the function and want to create a new column df['growth_factor'] which will have a derived value in it. The tricky part is that two other columns need to be passed in a function for every row.
import pandas as pd
df = pd.DataFrame({"city":["losangeles", "losangeles", "newyork"],
"beds":[3, 4, 4]})
def growth_factor(city,beds):
if beds==3:
if city == 'losangeles' : return 45
else: False
elif beds==4:
if city == 'losangeles' : return 47
elif city == 'newyork' : return 50
else: False
else: False
The function should pass into a df and should look like this:
df=
'city' | 'beds' | 'growth_factor'
losangeles |3 | 45
losangeles |4 | 47
newyork |4 | 50
How can I achieve this?