我有一个分层系列
如下
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/