【发布时间】:2015-07-30 14:35:15
【问题描述】:
我想使用第三列来衡量 pandas 交叉表中的结果。
例如:
import pandas as pd
df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar', 'bar'],
'B': [1, 1, 0, 0, 0],
'weight': [2, 3, 4, 5, 6]})
print(pd.crosstab(df.A, df.B))
结果:
B 0 1
A
bar 2 1
foo 1 1
我想要的结果是:
B 0 1
A
bar 11 3
foo 4 2
【问题讨论】:
标签: python pandas scipy crosstab statsmodels