add a binary column based on condition

  dataframe, python

I have a dataframe "veh_contract2_df" like this :

FUEL_CODE   FUEL_TYPE 
1           MARGE+PLUS
10          DIESEL

I would like to add a column "hybrid" which should contain "Y" if there is "+" in FUEL_TYPE and "N" if not.

sub_str = "+"
if(veh_contract2_df.loc[(veh_contract2_df['FUEL_TYPE'].find(sub_str)==-1)]):
    veh_contract2_df['HYBRIDE'] = "Y"
    else:
    veh_contract2_df['HYBRIDE'] ="N"

But i got this error : SyntaxError: invalid syntax (at line 71)

Any idea please? thanks

Source: Python Questions

LEAVE A COMMENT