从索引和列创建多索引

时间:2015-10-12 18:39:09

标签: python pandas indexing merge multi-index

我有一个multiIndex数据框,我正在与另一个multiIndex数据框合并,它已成功合并,但现在它只有一个索引?

climate_df2.index.names
Out[79]: FrozenList(['key', 'Y'])

fileformat_df.index.names
Out[80]: FrozenList(['key', 'Y'])

climate_df3 = pd.merge(climate_df2.reset_index(), fileformat_df.reset_index(),
                   on = ["key","Y"], how = "inner").set_index("key","Y")

climate_df3.index.names
Out[81]: FrozenList(['key'])

climate_df3.columns
Out[82]: Index(['Y', 'DatasetName', 'Organization', 'URL', 'FileFormat'], dtype='object')

但现在是前指数" Y"是合并数据框中的列。所以我要么让合并的DF首先返回两个索引,要么只添加列#34; Y"到合并的数据框。

1 个答案:

答案 0 :(得分:0)

刚想出如何“修复”它:

remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        Some possible problems:
remote:
remote:        - Dangerous semver range (>) in engines.node
remote:        https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:
remote:        Love,
remote:        Heroku
remote:
remote:
remote:  !     Push rejected, failed to compile Node.js app

我仍然不确定为什么“Y”会在列中结束,但这会将其放回MultiIndex中。