Pandas pivot table aggregation with 'size' gives an error “'Series' object has no attribute 'columns'”
问题 I have the following DataFrame: df = pd.DataFrame({'foo': [1, 3, 3, 4], 'bar': [2, 5, 8, 9], 'abc': [3, 7, 2, 4]}) When I tried using the command: df.pivot_table('bar', 'foo', aggfunc='size') I get the error: AttributeError: 'Series' object has no attribute 'columns' Strangely, the problem disappears when I aggregate several columns simultaneously: df.pivot_table(['bar', 'abc'], 'foo', aggfunc='size') But reappears again if I add the "dropna=False" parameter: df.pivot_table(['bar', 'abc'],