4

Say I have a DataFrame that looks something like this:

    A   B   key1    key2
0   A0  B0  K0  K0
1   A1  B1  K0  K1
2   A2  B2  K1  K0
3   A3  B3  K2  K1
4   A0  B0  K0  K0

I know that I can get the counts of unique values in the 'key1' column with this: df['key1'].value_counts() which returns something like this:

K0    3
K1    1
K2    1

But what if I want to get counts of combinations between the two key columns. To return something like this:

K0  K0    2
K0  K1    1
K0  K1    1
K0  K1    1
Cœur
  • 37,241
  • 25
  • 195
  • 267
The Nightman
  • 5,609
  • 13
  • 41
  • 74

0 Answers0