Sign check on pandas dataframe

Viewed 51

I have a dataframe (df) like this:

        A           B           C          D
0   -0.01961    -0.01412    0.013277    0.013277
1   -0.021173   0.001205    0.01659     0.01659
2   -0.026254   0.009932    0.028451    0.012826

How could I efficiently check if there is ANY column where column values do not have the same sign?

1 Answers

Check with np.sign and nunique

np.sign(df).nunique()!=1
Out[151]: 
A    False
B     True
C    False
D    False
dtype: bool
Related