我有一个包含许多不同元素的pandas数据框,我想对相似的元素进行分组并添加另一列来表示它们的出现频率。例如:
+-------+------+
| Atr1 | Atr2 |
+-------+------+
| 1 | A |
+-------+------+
| 2 | B |
+-------+------+
| 1 | A |
+-------+------+
| 3 | C |
+-------+------+
我想得到:
+-------+-------+-------+
| Atr1 | Atr2 | COUNT |
+-------+-------+-------+
| 1 | A | 2 |
+-------+-------+-------+
| 2 | B | 1 |
+-------+-------+-------+
| 3 | C | 1 |
+-------+-------+-------+
我该怎么办?