Imagine we have a dataframe like this:
import pandas as pd
df = pd.DataFrame()
df['filename'] = ['118_3.JPG', '118_3.JPG', '118_3.JPG', '118_3.JPG', '118_3.JPG', '15_7.JPG', '15_7.JPG', '15_7.JPG', '15_7.JPG', '15_7.JPG','203_4.JPG', '203_4.JPG', '203_4.JPG', '203_4.JPG', '203_4.JPG']
df['cvxh_len'] = [100, 200, 3000, 2800, 29, 200, 400, 2, 1, 0, 5000, 6000, 9000, 11000, 15000]
df['date'] = ["2018-12-14", "2018-12-15", "2018-12-16", "2018-12-17", "2018-12-18", "2018-12-14", "2018-12-15", "2018-12-16", "2018-12-17", "2018-12-18", "2018-12-14", "2018-12-15", "2018-12-16", "2018-12-17", "2018-12-18" ]
df["date"] = pd.to_datetime(df["date"])
df
filename cvxh_len date
118_3.JPG 100 2018-12-14
118_3.JPG 200 2018-12-15
118_3.JPG 3000 2018-12-16
118_3.JPG 2800 2018-12-17
118_3.JPG 29 2018-12-18
15_7.JPG 200 2018-12-14
15_7.JPG 400 2018-12-15
15_7.JPG 2 2018-12-16
15_7.JPG 1 2018-12-17
15_7.JPG 0 2018-12-18
203_4.JPG 5000 2018-12-14
203_4.JPG 6000 2018-12-15
203_4.JPG 9000 2018-12-16
203_4.JPG 11000 2018-12-17
203_4.JPG 15000 2018-12-18
How can we remove rows that have a decreasing cvxh_len value over time (date) for each unique filename so that we end up with the following:
filename cvxh_len date
118_3.JPG 100 2018-12-14
118_3.JPG 200 2018-12-15
118_3.JPG 3000 2018-12-16
15_7.JPG 200 2018-12-14
15_7.JPG 400 2018-12-15
203_4.JPG 5000 2018-12-14
203_4.JPG 6000 2018-12-15
203_4.JPG 9000 2018-12-16
203_4.JPG 11000 2018-12-17
203_4.JPG 15000 2018-12-18