Skip to content
Advertisement

Return columns that are binary in ndarray?

So for the same thing

JavaScript

does for a panda dataframe. I want to know how to do this when it is a ndarray?

1 40 0 0 0 0 0 0
2 58 0 0 1 0 0 0
3 41 0 1 1 0 0 1
4 45 0 0 1 1 0 1
5 60 0 1 0 1 0 1

JavaScript

This is the function for pandas dataframe how do i change getBinaryCol if passing data.values(ndarray) instead of only data?

Advertisement

Answer

The code below checks if each cell contains either 0‘s or 1‘s, allows both by using np.logical_or and checks if the condition is met for the whole column by using np.all.

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