如何在Python Pandas中获取groupby之后的所有组合键

时间:2016-08-22 09:51:52

标签: python pandas group-by

我希望在分组后拥有所有密钥组合,以便for(int i = 0; i < counts.length; i++) { char gradeAsChar = 'A' + i; System.out.println(gradeAsChar + ":"+ counts[i]); } 具有a个唯一值且na具有b个唯一值而不是输出行数应该是nb。我尝试了na*nbreindex,但它无效:

reindex_axis

我想得到:

>>> df = pd.DataFrame({'a': [1,1,2,3],'b':[1, 2, 3,4], 'c':[1,2,3,4]})
>>> df.groupby(['a','b']).count()
     c
a b  
1 1  1
  2  1
2 3  1
3 4  1

1 个答案:

答案 0 :(得分:6)

您可以使用reindex:

x.cpp: In instantiation of ‘void p<type>::f() [with type = int]’:
x.cpp:26:9:   required from here
x.cpp:19:13: error: invalid use of unary ‘*’ on pointer to member
     cout << *q;
             ^
相关问题