1

私はHierarchical Series以下のように持っています

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]])

新しいシリーズを挿入したいdata

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

私が試してみました

data['e'] = t_series 

Hierarchical Seriesしかし失敗しました。動的に拡大する方法を教えてもらえますか?

4

2 に答える 2

1

それを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()

ドキュメントにあるように: ASeries1 次元のラベル付き配列ですが、aDataFrameは潜在的に異なる型の列を持つ2 次元のラベル付きデータ構造です。

于 2013-02-11T08:51:47.277 に答える
0

単純に第 2 レベルのインデックスを にしたい場合は、次のrange(10)ようにする必要があります。

t_series = pd.Series(np.random.randn(10), index=[('e ' * 10).split(), range(10)])
t_series

次に使用しますconcat

pd.concat([data, t_series])
于 2013-02-11T09:12:39.093 に答える