Skip to content
Advertisement

Replace zero values on all columns if sum of that columns is greater than 1?

I have CSV files like following

JavaScript

I want to replace Result1, Result2, and Result3 columns by all zero if the sum of their column values is greater than 1. I tried this script

JavaScript

When I do this operation Result3 column is dropped since it has all zero values. How do I do this operation only on the columns which satisfy the condition without affecting another column which didn’t satisfy the condition?

Advertisement

Answer

JavaScript

gives

JavaScript

In your example dataframe, this makes all columns zero. To see that this is not always the case, put a 1 in the last column and verify that it survives the operation.

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