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 ?