Python Pandas Count columns with multiple conditions and groupby

preview_player
Показать описание
Python Pandas Count columns with multiple conditions and groupby

Рекомендации по теме
Комментарии
Автор

Hi, for example I have a table, which I've got by left outer join:

person - vehicle

dad - car
dad - motorcycle
dad - bicycle
mom - car
mom - bicycle
son - None/NA/NaN/NaT

How to group by person and count with condition (car and motorcycle)?

When I use for example:
df = x: x[x == 'car'].count())

But I can't use a list in condition lambda x: x[x in ['car']], pandas says:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

georgiyveter
welcome to shbcf.ru