假设我有一个 DataFrame,例如,
In [7]: source = pd.DataFrame([['amazon.com', 'correct', 'correct'], ['amazon.com', 'incorrect', 'correct'], ['walmart.com', 'incorrect', 'correct'], ['walmart.com', 'incorrect', 'incorrect']], columns=['domain', 'price', 'product'])
In [8]: source
Out[8]:
domain price product
0 amazon.com correct correct
1 amazon.com incorrect correct
2 walmart.com incorrect correct
3 walmart.com incorrect incorrect
我想为每个 计算和domain
的次数price == 'correct'
,price == 'incorrect'
对于product
。换句话说,我希望看到这样的输出,
domain key value count
0 amazon.com price correct 1
1 amazon.com price incorrect 1
2 amazon.com product correct 2
3 walmart.com price incorrect 2
4 walmart.com product correct 1
5 walmart.com product incorrect 1
我该怎么做呢?