I would like to use a third column to weight results in a pandas crosstab.
For example, the following:
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))
results in:
B 0 1
A
bar 2 1
foo 1 1
What I would like as a result is:
B 0 1
A
bar 11 3
foo 4 2