I have a dataframe (df) as follows:
d = {'Item':['x','y','z','x','z'], 'Count' : ['10', '11', '12', '9','10'], 'Date' : pd.to_datetime(['2018-8-14', '2018-8-14', '2018-8-14', '2018-8-13','2018-8-13'])}
df= pd.DataFrame(data=d)
Item Count Date
x 10 2018-08-14
y 11 2018-08-14
z 12 2018-08-14
x 9 2018-08-13
x 9 2018-08-12
z 10 2018-08-13
I want to compare rows based on the following:
For each item, compare the count of max(Date) with max(Date) - 1.
Meaning it should compare the count for item x, for dates 2018-08-13 and 2018-08-14. If the count for max(Date) is greater then it should select that row and store it in a different dataframe.
Same for item z, it should compare the counts for dates 2018-08-13 and 2018-08-14 and because the count is greater it should select the row for item z with count 12.
Output: df2
Item Count Date
x 10 2018-08-14
z 12 2018-08-14
I've tried the following:
if ((df.Item == df.Item) and
(df.Date > df.Date) and (df.Count > df.Count)):
print("we met the conditions!")