vendredi 18 mai 2018

if condition + check isnull() is true

I have a df that looks like this:

     carry_dt    sedol    prime_broker_id  legal_entity   strategy  NewCarryRate  
716   2018-01-02  B1T84Z4    CITI             USSA-AGG      USSA       NaN

I would like to check if there are any NaN values in the column 'NewCarryRate' and replace them

I created an if condition:

 if (allHoldings['NewCarryRate'].iloc[[i]].isnull())==True:
        allHoldings['NewCarryRate'].values[i]= 100

I get an error saying:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

I know I can use np.where but I find it easier to use if condition here because I can add more rows under the if condition if I wanted to.

Many Thanks for your help

Aucun commentaire:

Enregistrer un commentaire