I'm making some crosstabs with pandas:
a = np.array(['foo', 'foo', 'foo', 'bar', 'bar', 'foo', 'foo'], dtype=object)
b = np.array(['one', 'one', 'two', 'one', 'two', 'two', 'two'], dtype=object)
c = np.array(['dull', 'dull', 'dull', 'dull', 'dull', 'shiny', 'shiny'], dtype=object)
pd.crosstab(a, [b, c], rownames=['a'], colnames=['b', 'c'])
b one two
c dull dull shiny
a
bar 1 1 0
foo 2 1 2
But what I actually want is the following:
b one two
c dull shiny dull shiny
a
bar 1 0 1 0
foo 2 0 1 2
I found workaround by adding new column and set levels as new MultiIndex, but it seems to be difficult...
Is there any way to pass MultiIndex to crosstabs function to predefine output columns?