I have a following DataFrame:
import pandas as pd
stuff = [
{"num": 4, "id": None},
{"num": 3, "id": "stuff"},
{"num": 6, "id": None},
{"num": 8, "id": "other_stuff"},
]
df = pd.DataFrame(stuff)
I need to select rows where "num" is higher than a given number but only if "id" is not None:
This doesn't have any effect:
df = df.loc[df["num"] >= 5 & ~pd.isnull(df["id"])]
What I need is something like this (presudocode):
df = df.loc[
if ~pd.isnull(df["id"]):
if df["num"] >= 5:
select row
]
The expected result:
>>> df
id num
1 stuff 3
2 None 6
3 other_stuff 8
Any help appreciated.