简体   繁体   English

将多索引系列附加到熊猫中的空系列

[英]Appending multi-indexed Series to an empty Series in pandas

I take a multi-indexed pandas series named 'dat' and try to append it to an empty series named 's'. 我选择了一个名为“ dat”的多索引熊猫系列,并尝试将其附加到一个名为“ s”的空系列中。 This is how 'dat' looks like: 这是“ dat”的样子:

a = [['bar', 'bar', 'foo', 'foo'],['one', 'two', 'one', 'two']]
t = list(zip(*a))
ind = pd.MultiIndex.from_tuples(t, names=['first', 'second'])
dat = pd.Series(randn(4), index=ind)

Out[1]: 
first  second
bar    one      -1.361606
       two      -0.108458
foo    one      -0.691175
       two      -0.830161
dtype: float64

Now, when I append it to the empty Series 's' it returns this: 现在,当我将其附加到空Series时,它将返回以下内容:

s = pd.Series()
s = s.append(dat)
Out[2]: 
(bar, one)   -1.361606
(bar, two)   -0.108458
(foo, one)   -0.691175
(foo, two)   -0.830161
dtype: float64

How can I recover the original form? 如何恢复原始表格?

This was a bug fixed in 0.14.0 (coming next week), see here: http://pandas-docs.github.io/pandas-docs-travis/whatsnew.html#whatsnew-0140-api (the set_index section). 此错误已在0.14.0(下周发布)中修复,请参见此处: http ://pandas-docs.github.io/pandas-docs-travis/whatsnew.html#whatsnew-0140-api(set_index部分) 。

You can get the pre-release here: https://github.com/pydata/pandas/releases 您可以在此处获取预发布版本: https//github.com/pydata/pandas/releases

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM