1
I have a dataframe with (1242 Rows 325 Columns) of it I make a correlation ". Corr()" which results in (325 Rows 325 Columns)
this code shows me the 15 smallest correlations of the lowest value for the highest value based on "ABEV3" (15 Rows 1 Columns)
ppl = 'ABEV3'
papel = corr[ppl]
corr.query('@papel < 0.1')[ppl].sort_values(ascending=True).head(n=15).index.to_frame().rename(columns={0: ppl})
ABEV3
PATI3 PATI3
ENMT3 ENMT3
RNEW11 RNEW11
CEDO3 CEDO3
RNEW3 RNEW3
BDLL4 BDLL4
CAMB3 CAMB3
ESTR4 ESTR4
CAMB4 CAMB4
SPRI3 SPRI3
DTCY3 DTCY3
MAPT4 MAPT4
BMEB3 BMEB3
ELEK4 ELEK4
LIPR3 LIPR3
My difficulty is to list (15 Rows 326 Columns) each column being correlated and in the first column being numbered by the number of lines, an example done manually:
ppl = corr.columns # lista/exibe os indexes das colunas
# executando ppl
ppl
Index(['^BVSP', 'AALR3', 'ABCB4', 'ABEV3', 'ADHM3', 'AGRO3', 'ALPA3', 'ALPA4',
'ALSO3', 'ALUP11',
...
'VLID3', 'VULC3', 'VVAR3', 'WEGE3', 'WHRL3', 'WHRL4', 'WIZS3', 'WLMM4',
'WSON33', 'YDUQ3'],
dtype='object', length=325)
papel = corr[ppl]
corr.query('@papel < 0.1')[ppl].sort_values(ascending=True).head(n=15).index.to_frame().rename(columns={0: ppl})
# quero que o resultado saia com essa estrutura
ABEV3 PATI3 ITUB4
1 PATI3 MRSA3B REDE3
2 ENMT3 FLRY3 ESTR4
3 RNEW11 MGLU3 CAMB3
4 CEDO3 SPRI3 DTCY3
5 RNEW3 TUPY3 ENMT3
6 BDLL4 CRPG6 CEDO3
7 CAMB3 USIM3 NORD3
8 ESTR4 TASA4 ELEK4
9 CAMB4 CAMB4 CAMB4
10 SPRI3 LLIS3 CTNM3
11 DTCY3 GEPA4 BMEB3
12 MAPT4 SLED3 MAPT4
13 BMEB3 CPLE6 PATI3
14 ELEK4 PTNT4 SPRI3
15 LIPR3 INEP4 PATI4
I can not fit this line within a FOR, or some means that can return me as the example I mentioned, I have a few months that I have been learning, my repetition structure is very vague.