'Python Dataframe remove rows based on function return
One of the columns in my dataframe includes a link. I have a function that will return true/false depending on if the link is valid (example- it doesnt return a 404 error). I have tried df.drop and df.apply and both of them created issues I couldn't fix. Here is the closest Ive gotten.
df.drop((i for i in df['Column_Name'] if not check_link_valid(i)), axis=1, inplace=True)
Currently, this is the error I get.
KeyError(f"{labels[mask]} not found in axis")
An alternative solution could be changing a value in one of the other columns of the row or adding a column with the value corresponding to the value returned from the function.
Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
