I am trying to apply function which refers to 2 columns to a pandas dataframe. One column that that the function is referring to has string variables, other integers.
I am getting a following error ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Below is the example of what I have tried so far
def sd2_offshore(gas_rate,platform):
if platform=='Stage2':
if 0<gas_rate<900:
return 5
elif gas_rate>900:
return 6
else:
return 0
else:
return 0
df2['Offshore SD2']=df2.apply(lambda row : sd2_offshore(df2['Gas_Rate_avg'],df2['Platform']))
df2['Platform']
contains string values.
df2['Gas_Rate_avg']
contains integer values
Thanks a lot in advance!
Edit
Adding example of the data below
Index Platform Gas_Rate_avg
0 Stage2 300
1 Stage2 0
2 Stage2 1100
3 Stage2 1200
4 Stage1 500
Expected output:
Index Platform Gas_Rate_avg Offshore_SD2
0 Stage2 300 5.00
1 Stage2 0 0.00
2 Stage2 1100 6.00
3 Stage2 1200 6.00
4 Stage1 500 0.00