You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [1]: import pandas as pd
In [2]: df = pd.DataFrame({'a': ['a1', 'a2', 'a3'], 'b': [1,2,3], 'c':['c1', 'c2', 'c3']})
In [3]: x = df[df['c'] == 'c1']
In [4]: y = x.pivot_table(index='a', columns='c', values='b')
In [5]: y.columns
Out[5]: Index([u'c1'], dtype='object', name=u'c')
In [6]: x = df[df['c'] == 'c4']
In [7]: y = x.pivot_table(index='a', columns='c', values='b')
In [8]: y.columns # returns a multi-index, should not
Out[8]:
MultiIndex(levels=[[u'b'], []],
labels=[[], []],
names=[None, u'c'])
# a check was added for empty dataframe that is causing the behavior, works in 0.16.2
> /auto/energymdl2/anaconda/envs/commod_20160516_pd18/lib/python2.7/site-packages/pandas/tools/pivot.py(161)pivot_table()
159
160 # discard the top level
--> 161 if values_passed and not values_multi and not table.empty:
162 table = table[values[0]]
163
Expected Output
In [5]: y.columns
Out[5]: Index([], dtype='object', name=u'c')
Code Sample, a copy-pastable example if possible
Expected Output
output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: