在set_index之后组织MultiIndex DataFrame

时间:2017-12-13 11:03:33

标签: python pandas structure multi-index

我将数据存储在SQL数据库中。当我调用这些数据时,它会作为DataFrame返回给我(我正在使用pandas)。

然后我将set_index组织为MultiIndex级别的DataFrame。

data.set_index(['colname1', 'colname2', 'colname3'],inplace=True)

但是,我的数据并没有完全有条理地形成。意思是我希望以这种方式存储这些数据:

我希望如何:

enter image description here

目前它以这种方式返回,采用非有组织的方式:

enter image description here

0 个答案:

没有答案
相关问题