gpt4 book ai didi

python - 如何将系列添加到分层系列

转载 作者:太空宇宙 更新时间:2023-11-03 19:05:37 24 4
gpt4 key购买 nike

我有一个分层系列如下

data=pd.Series(np.random.randn(10),
index=[['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'd', 'd'],
[1, 3, 4, 1, 2, 3, 1, 2, 2, 3]])

我想将一个新系列插入数据

t_series = pd.Series(np.random.randn(10))

我已经尝试过

data['e'] = t_series 

但是失败了,有人可以告诉我如何动态放大Hierarchical Series吗?

最佳答案

将其设为 DataFrame :

df = pd.DataFrame(data)

df['e'] = np.random.randn(10)
# or if you already created another series, which perhaps has a different index
df['e'] = t_series.values()

作为 docs注:ASeries是一个一维标记数组,而DataFrame是一个二维标记数据结构,其中包含可能不同类型的列。

关于python - 如何将系列添加到分层系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14808354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com