1

I have a dataframe:

 df5=pd.DataFrame( {'a':[1,2,3,4], 'b':[5,np.nan,np.nan,8] }, index=pd.date_range('7-23-2020', periods=4, name='date')) a b date 2020-07-23 1 5.0 2020-07-24 2 NaN 2020-07-25 3 NaN 2020-07-26 4 8.0 

I want to select np.nan values in 'b' column and replace with corresponding vales in 'a'. This my code:

df5.loc[df5['B'].isna(),'B']=df5.loc[df5['B'].isna(),'A']*100 

Is this code a good practice?

1 Answer 1

3

A better solution would be to use:

df5['b'] = df5.b.fillna(df5.a*100) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.