【发布时间】:2018-03-05 20:11:06
【问题描述】:
我有一个带有多索引的pandas.Series:
index = pd.MultiIndex.from_tuples([('one', 'a'), ('one', 'b'),
('two', 'a'), ('two', 'b')])
s = pd.Series(np.arange(1.0, 5.0), index=index)
print(s)
one a 1.0
b 2.0
two a 3.0
b 4.0
dtype: float64
我想将多索引合并成单个索引,格式如下:
one_a 1.0
one_b 2.0
two_a 3.0
two_b 4.0
dtype: float64
有什么好的方法吗?
【问题讨论】: