How to use a specific column value in a Pandas DataFrame where clause?

I am trying to select all cells in a pandas DataFrame that match certain criteria when a particular column also matches individual criteria.

Given the following DataFrame:

      A    B    C    D
1/1   0    1    0    1
1/2   2    1    1    1
1/3   3    0    1    0 
1/4   1    0    1    2
1/5   1    0    1    1
1/6   2    0    2    1
1/7   3    5    2    3

I would like to somehow select the data where the column is larger than its previous value, when Dalso> 1. The syntax I'm trying to use at the moment is:

matches = df[(df > df.shift(1)) & (df.D > 1)]

However, when I do this, I get the following error:

TypeError: failed to use [array ([nan, nan, nan, nan], dtype = object)] with block values ​​[operands cannot be passed along with forms (2016) (4)]

: , DataFrame.

, df.D > 1 , D (df > df.D ). D 1 ?

+3
2

, pandas ( 0.14). .

In [74]: df
Out[74]: 
     A  B  C  D
1/1  0  1  0  1
1/2  2  1  1  1
1/3  3  0  1  0
1/4  1  0  1  2
1/5  1  0  1  1
1/6  2  0  2  1
1/7  3  5  2  3

, , np.nan, False

In [78]: x = df[df>df.shift(1)]

In [79]: x
Out[79]: 
      A   B   C   D
1/1 NaN NaN NaN NaN
1/2   2 NaN   1 NaN
1/3   3 NaN NaN NaN
1/4 NaN NaN NaN   2
1/5 NaN NaN NaN NaN
1/6   2 NaN   2 NaN
1/7   3   5 NaN   3

In [80]: x[df.D>1]
Out[80]: 
      A   B   C  D
1/4 NaN NaN NaN  2
1/7   3   5 NaN  3
+3

, , . false , .

,

DF.dtypes

, int,

0

All Articles