值为dataframe的字典交换键与dataframe的列——通过Panel实现

dic={}
for st in set([i[0] for i in pd.Panel(df_factor_pre_train).to_frame().index.tolist()]):
    df=pd.Panel(df_factor_pre_train).to_frame().query('code==@st')
    a=df.reset_index()
    a.index=a.minor
    del a['code'],a['minor']
    dic[st]=a
原文地址:https://www.cnblogs.com/Yangami/p/14838764.html