I have a pandas dataframe, "tracks", that I'm filtering for erroneous altitude information. When the altitude is below a certain criteria, I want to throw out all rows that start with the same track_key. In the example, N123P, on track_key 4xuut, has an erroneous altitude, so I want to remove ALL rows that start with "4xuut", but NOT the rows below them that have the same call sign.
| track_key | callsign | aircraft_type | speed | altitude |
|---|---|---|---|---|
| 4xuut | N123P | C550 | 300 | -1 |
| 4xuut | N123P | C550 | 297 | 15 |
| 4yt06 | N123P | C550 | 305 | 1022 |
| 4yt06 | N123P | C550 | 301 | 1028 |
| 4xx21 | N348U | GALX | 350 | 1025 |
I've tried this:
tracks = tracks[tracks.track_key != tracks.loc[tracks['altitude'].astype('float') <= field_elev, 'track_key'].iloc[0]], but it only seems to work on the first match (there can be several), or, if there are no matches, I get an "out-of-bounds" error.