jeudi 28 décembre 2017

if logic in pandas, Python3

I've got a Pandas Dataframe from which I want to compare two columns and create a new column with a calculation based off the result of the comparison. Logic would be the following:

If df['column1']>df['column2'] :
   df['New column']=(df['column1']+df['column2'])
else :
   df['New column']=(df['column1']+df['column2']+1)

I am fairly new to pandas and Python so I'm sure I'm getting the structure wrong. Could you guys pint me in the right direction?

Thanks!

Aucun commentaire:

Enregistrer un commentaire