Consider the following dataframe:
test = pd.DataFrame({'A': [datetime.datetime.now(), datetime.datetime.now()], 'B': [1, 2]})
If I use pivot_table like below then everything is fine:
test.pivot_table(index = 'A', aggfunc = {'B': 'mean'}, margins = True)
However, if I do the following, I can't set margins = True (throws the error KeyError: 'A'):
test.pivot_table(index = test['A'], aggfunc = {'B': 'mean'}, margins = True)
I am really confused. Let's say I need do something like below AND need to set margin = True. Is that impossible?
test.pivot_table(index = test['A'].dt.year, aggfunc = {'B': 'mean'}, margins = True)