Skip to content

creating Panel from dict of DataFrames loses dtypes #359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CRP opened this issue Nov 11, 2011 · 1 comment
Closed

creating Panel from dict of DataFrames loses dtypes #359

CRP opened this issue Nov 11, 2011 · 1 comment
Milestone

Comments

@CRP
Copy link
Contributor

CRP commented Nov 11, 2011

in the example below, "a" is a mixed type dataframe. Once included in the Panel, all columns become of type object:

In [249]: a=DataFrame(randn(30,3),columns=('a','b','c'))

In [250]: b=DataFrame(randn(30,3),columns=('a','b','c'))

In [251]: a['b']=a['b'].astype(object)

In [252]: a.dtypes
Out[252]:
a float64
b object
c float64

In [253]: b.dtypes
Out[253]:
a float64
b float64
c float64

In [254]: Panel({'1':a,'2':b})['1'].dtypes
Out[254]:
a object
b object
c object

In [255]: Panel({'1':a,'2':b})['2'].dtypes
Out[255]:
a float64
b float64
c float64

@wesm
Copy link
Member

wesm commented Nov 11, 2011

Panel can only be heterogeneous in the items. I just added an orient option to Panel so you can do:

In [4]: panel = Panel.from_dict({'1':a,'2':b}, orient='minor')

In [5]: panel
Out[5]: 
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 30 (major) x 2 (minor)
Items: a to c
Major axis: 0 to 29
Minor axis: 1 to 2

In [6]: panel['a'].values.dtype
Out[6]: dtype('float64')

In [7]: panel['b'].values.dtype
Out[7]: dtype('object')

In [8]: panel['c'].values.dtype
Out[8]: dtype('float64')

@wesm wesm closed this as completed Nov 11, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants