lundi 7 septembre 2015

Pandas If Statements (excel equivalent)

I'm trying to create a simple if statement in Pandas.

The excel version is as follows:

=IF(E2="ABC",C2,E2)

I'm stuck on how to assign it based on a string or partial string.

Here is what I have.

df['New Value'] = df['E'].map(lambda x: df['C'] if x == 'ABC' else df['E']]

I know I'm making a mistake here.

As the outcome is the entire dataframe values in each cell.

Any help would be much appreciated!

Aucun commentaire:

Enregistrer un commentaire