Я считаю, что иерархические индексы мешают определенным задачам (например, этой), и лучше выполнять все манипуляции на плоском фрейме данных. В следующих шагах я использую reset_index
, чтобы превратить уровни индекса в обычные столбцы, а затем set_index
, чтобы вернуть их обратно при подготовке к этапу построения графика.
# reset the indexes, and add a new column to both dataframes
df1.reset_index(inplace=True)
df1['Plant Type'] = 'Operational'
df2.reset_index(inplace=True)
df2['Plant Type'] = 'Pipeline'
# concatenate the two dataframes
df_combined = pd.concat([df1, df2])
# set the index back to how it was, but also include the new column, and then plot
df_combined.set_index(['Plant Type', 'Country', 'Fuel']).plot.area()