Skip to content
Advertisement

combine pd.loc and pd.iloc to assign value

My input:

JavaScript

I try assign new value based on other column in this way it work:

dd.loc[dd.iloc[:,1]==0,['result_'+cv_detail[0]] ] = 'Other' OR dd.loc[dd.sum_result_ICV == 0, "result_ICV"] = 'Other'
But this code doesn’t, code make more columns, with assign new value into column:

JavaScript

What difference?

Advertisement

Answer

Use double iloc first for select second column by dd.iloc[:,1], conmvert to numpy array for possible assign in another iloc for fourth column (3):

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement