pydata/pandas — pull request #8103 by sinhrks (2014-08-23 12:22:07+00:00)
Title: BUG: pivot_table raises KeyError with nameless index and columns

``pivot_table`` raises ``KeyError`` when args passed to ``index`` and ``columns`` don't have ``name`` attribute. The fix looks especially useful when pivotting by ``dt`` accessor.

```
df = pd.DataFrame({'dt1': [datetime.datetime(2011, 1, 1), datetime.datetime(2011, 2, 1),
datetime.datetime(2011, 3, 1), datetime.datetime(2011, 4, 1),
datetime.datetime(2011, 5, 1), datetime.datetime(2012, 1, 1),
datetime.datetime(2012, 2, 1), datetime.datetime(2012, 3, 1),
datetime.datetime(2012, 4, 1)],
'col1': 'A A A B B B C C C'.split(),
'val1': [1, 2, 3, 4, 5, 6, 7, 8, 9]})

pd.pivot_table(df, index=df['dt1'].dt.month, columns=df['dt1'].dt.year, values='val1'))
# KeyError: 'Level None not found'
```

### After fix
```
pd.pivot_table(df, index=df['dt1'].dt.month, columns=df['dt1'].dt.year, values='val1'))
# 2011 2012
# 1 1 6
# 2 2 7
# 3 3 8
# 4 4 9
# 5 5 NaN
```