? ? df_target = pd.DataFrame(df_pct[(df_pct.ts_code == code)].sort_values(by=['date'],ascending=False)) ? ? df_xiang = pd.DataFrame(df_target['ts_code'].head(1)) ? ? df_hebing = pd.merge(df_pct,pivot_df,on=['date'],how='inner') ? ? df_hebing = df_hebing[:-1] ? ? df_corr = pd.DataFrame(df_hebing.corr()['pct_chg']).sort_values(by=['pct_chg'],ascending=False) ? ? df_corr.index.name='var' ? ? df_corr = df_corr.reset_index() ? ? var = df_corr['var'].values[1]#实际是第二行 ? ? df_corr_2 = pd.DataFrame(df_corr['var'].iloc[[1]]) ? ? df21 = df_xiang.reset_index()[['ts_code']] ? ? df22 = df_corr_2.reset_index()[['var']] ? ? df33 = pd.DataFrame(pd.concat([df21,df22],axis=1)) ? ? data = data.append(df33)
一是要reset_index,一是要concat,不然都会错
|