Suppose I have a df with 2 columns A and B and a class Foo() which can be instantiated by A’s value. I’d like to get a unique series of B which satisfy Foo(A).item.price == 0.
I tried the following code which obviously doesn’t work.
unique_B = df.loc[Foo(df.A.str).item.price == 0, "B"].unique()
I guess I could create a third column to store the value of foo(df.A), is there a simpler solution?
df.A.apply(foo) instead of
unique_B = df.loc[df.A.apply(foo) == 0, "B"].unique()
To access the
item property of the
unique_B = df.loc[df.A.apply(lambda x: foo(x).item.price) == 0, "B"].unique()
Answered By – richardec
Answer Checked By – Cary Denson (BugsFixing Admin)