将多行多列转成多行一列,即多层索引

group_data_dict = {}
for name, group in factor_data.groupby(color[color.columns[0]]):
    iterable = [group.iloc[:, 0].tolist(), group.columns[1:].tolist()]
    group_data = pd.DataFrame(group.iloc[:, 1:].values.reshape(-1),
                              index=pd.MultiIndex.from_product(iterable, names=['glass_id', 'measure_point']),
                              columns=['measure_value'])
    group_data2 = group_data.reset_index()
    cols = ['measure_value', 'glass_id', 'measure_point']
    group_data3 = group_data2.loc[:, cols]

你可能感兴趣的:(python)