【发布时间】:2015-01-27 08:30:36
【问题描述】:
>new_dat=dat_corr.merge(dat_class,on="Asset",how="right").set_index(['Country','Class','Asset'])
>new_dat.shape
(89, 89)
>temp1='UNITEDSTATES'
>temp2='Equity'
>new_dat.loc[ (new_dat.index.get_level_values('Country').isin([temp1]) & new_dat.index.get_level_values('Class').isin([temp2]))]'
>new_dat.columns=new_dat.index
最后一行给了我 [3 行 x 89 列]。我的 89 列是 Equity/FX/FI/Commodities 的组合。如果我只想要美国股票而不是所有其他股票而不是整个 89 列,我该怎么做? 我还为列添加了多索引。现在的问题是我沿行和列都有多个索引我如何使用它进行过滤 以下是一小部分数据:
国家 美国 加拿大 \
类股权 股权
资产 DJ1Index SP1Index ND1Index PT1Index
国家级资产
美国股票 DJ1Index 1.000000 0.958038 0.747192 0.648373
SP1指数 0.958038 1.000000 0.825458 0.717545
ND1指数 0.747192 0.825458 1.000000 0.612487
加拿大股票 PT1 指数 0.648373 0.717545 0.612487 1.000000
墨西哥股票 IS1 指数 0.622570 0.664499 0.565702 0.575618
国家 墨西哥 巴西 德国 英国 \
类别 股权 股权 股权 股权
资产 IS1Index BZ1Index VG1Index Z1Index
国家级资产
美国股票 DJ1指数 0.622570 0.523704 0.566993 0.520526
SP1指数 0.664499 0.565941 0.587933 0.539138
ND1指数 0.565702 0.484441 0.458135 0.391391
加拿大股票 PT1 指数 0.575618 0.526663 0.499343 0.493260
墨西哥股票 IS1 指数 1.000000 0.577041 0.502558 0.487487
【问题讨论】:
标签: python pandas multi-index