Skip to content

BUG: reshape of categorical via unstack/to_panel #8704

Closed
@davidrpugh

Description

@davidrpugh

I have a hierarchical pandas.DataFrame that looks as follows...

In [12]: data.tail()
Out[12]: 
                         country    currency_unit         rgdpe  \
countrycode year                                                  
ZWE         2007-01-01  Zimbabwe  Zimbabwe Dollar  45666.082031   
            2008-01-01  Zimbabwe  Zimbabwe Dollar  35789.878906   
            2009-01-01  Zimbabwe  Zimbabwe Dollar  49294.878906   
            2010-01-01  Zimbabwe  Zimbabwe Dollar  51259.152344   
            2011-01-01  Zimbabwe  Zimbabwe Dollar  55453.312500   

I would like to turn data into a pandas.Panel object. Previously I would do this using the to_panel method without issue. However, after upgrading to Pandas 0.15, this approach no longer works...

In [13]: data.to_panel()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-dfa9fb7a4e83> in <module>()
----> 1 data.to_panel()

/Users/drpugh/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in to_panel(self)
   1061                 placement=block.mgr_locs, shape=shape,
   1062                 labels=[major_labels, minor_labels],
-> 1063                 ref_items=selfsorted.columns)
   1064             new_blocks.append(newb)
   1065 

/Users/drpugh/anaconda/lib/python2.7/site-packages/pandas/core/reshape.pyc in     block2d_to_blocknd(values, placement, shape, labels, ref_items)
   1206 
   1207     if mask.all():
-> 1208         pvalues = np.empty(panel_shape, dtype=values.dtype)
   1209     else:
   1210         dtype, fill_value = _maybe_promote(values.dtype)

TypeError: data type not understood

Has there been an API change? I could not find anything in the release notes to suggest that the above would no longer work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugCategoricalCategorical Data TypeReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions