I'm trying to do the following: "# drop all rows where tag == train_loop and start is NaN".
Here's my current attempt (thanks Copilot):
# drop all rows where tag == train_loop and start is NaN
# apply filter function to each row
# return True if row should be dropped
def filter_fn(row):
return row["tag"] == "train_loop" and pd.isna(row["start"]):
old_len = len(df)
df = df[~df.apply(filter_fn, axis=1)]
It works well, but I'm wondering if there is a less verbose way.