如何在python中使用pandas合并表索引名?

如何在python中使用pandas合并表索引名?,python,pandas,prettytable,Python,Pandas,Prettytable,我想在一个索引中设置两列及其索引。但我不能合并表索引。如何使用pandas或row python代码合并表索引 我试着得到这个 下面是使用PrettyTable的示例代码 我想要的是: 您可以创建新的多索引(用于列),例如从元组: cols = pd.MultiIndex.from_tuples([ ('August', 'Invoice'), ('August', 'Sells'), ('September', 'Invoice'), ('September', 'Sells'

我想在一个索引中设置两列及其索引。但我不能合并表索引。如何使用pandas或row python代码合并表索引

我试着得到这个

下面是使用PrettyTable的示例代码

我想要的是:

您可以创建新的多索引(用于列),例如从元组:

cols = pd.MultiIndex.from_tuples([
    ('August', 'Invoice'), ('August', 'Sells'),
    ('September', 'Invoice'), ('September', 'Sells'),
    ('Growth', '1'),  ('Growth', '2') ])
然后将其设置为df中的列:

df.columns = cols