I have the following data (just a quick picture, numbers continue):
import pandas as pd
df = pd.DataFrame({'Flight Day': ['2018-10-01', '2018-10-01','2018-10-01', '2018-10-01', '2018-10-02','2018-10-02', '2018-10-02', '2018-10-02', '2018-10-03','2018-10-03','2018-10-03','2018-10-03'],
'Flight Number': ['CA1336', 'CA1332', 'CA1472', 'CA1473', 'CA1355', 'CA1331', 'CA1666', 'CA1665', 'CA1366', 'CA1337', 'CA1489', 'CA1667'],
'STD Departure': [10, 15, 8, 11,10, 15, 8, 14,10, 15, 8, 11],
'Bircher': [2, 4, 8, 4,3, 2, 3, 1,5, 5, 2, 1],
'Carac': [2, 4, 8, 4,2, 2, 3, 4,2, 5, 2, 1]})
I only want to keep the last 10 occurrences of the same "Flight Number" and "STD Departure" and delete the rows before the last 10 occurrences. For example, delete the rows for LX1336 (Flight Number) 10 (STD Departure) after before I have the last 10 rows that already qualify, hence have LX1336 (Flight Number) 10 (STD Departure). I have all flight numbers in a CSV document and STD Departure always go from 0 to 23 if that helps. Is there a short and crisp code for this problem? Thank you very much for your help!