I'm trying to aggregate a dataset in which one of the columns contains some URLs. Consider the following dataset
import pandas as pd
df = pd.DataFrame({"ID": [1, 1, 1, 2, 2],
"Website": ["https://www.auctionbid.com",
"https://www.google.com",
"https://www.awesomeauctions.net",
"https://www.awesomeauctions.net",
"http://www.auctionnoitcua.com"
]
})
I would like to perform the following analysis:
(
df
.groupby("ID")
.agg({"Website": lambda x:
"; ".join([site for site in x if x.str.contains("auction")])
})
)
This results in a ValueError
stating that the truth value of a Series is ambiguous. The accepted answer of this question states that if
can implicitly convert the operands to bool
, and suggests using "bitwise" operators.
My question, then, is how do I implement the equivalent of &
and |
for if
?