0

I have an array, but I need to transform it into an 11x11 matrix, how to do this?

d = {'Ambev': retornoAmbev, 'Bardell': retornoBardell,
     'Bombril': retornoBombril,'Braskem': retornoBraskem,
     'Petrobras': retornoPetrobras,'Vale': retornoVale,
     'Ibovespa': retornoIbovespa,'Poupança': retornoPoupança,
     'CDI': retornoCDI,'SELIC': retornoSelic}

df = pd.DataFrame(data=d)

pdCOV = df.cov()

array_matrix = np.array(pdCOV.to_records().view(type=np.matrix))

print(array_matrix)

[[('**Ambev**',  0.08289085, -0.01172982,  4.95575325e-02,
-0.06989391, -0.01660989, 0.01540076, -1.53656407e-03, -0.00048712, -0.00114877, -0.00252005)   ('**Bardell**', -0.01172982,  0.23285772, -2.21704237e-02,  0.21875916,  0.09834272, 0.09632943,  1.00698681e-01, -0.0010374 , -0.00328011, -0.0007994 )   ('**Bombril**',  0.04955753, -0.02217042,  6.42064182e-01,
-0.10951718, -0.0422506 , 0.05588981, -1.20970487e-02, -0.00015539,  0.00085053, -0.00155864)   ('**Braskem**', -0.06989391,  0.21875916, -1.09517183e-01,  2.54048926,  0.3457639 , 0.2842912 ,  4.64263877e-01, -0.00413512,  0.00493075,  0.0184824 )   ('**Petrobras**', -0.01660989,  0.09834272, -4.22505956e-02, 
0.3457639 ,  0.14561048, 0.09786241,  1.17554252e-01,  0.00035834,  0.00462521,  0.00829757)   ('**Vale**',  0.01540076,  0.09632943,  5.58898052e-02,  0.2842912 ,  0.09786241, 0.15037262,  1.11523118e-01,  0.0020628 ,  0.00724026,  0.00776359)   ('**Ibovespa**', -0.00153656,  0.10069868, -1.20970487e-02,  0.46426388,  0.11755425, 0.11152312,  1.41349400e-01, -0.00066876, -0.00019338,  0.0018708 )   ('**Poupança**', -0.00048712, -0.0010374 , -1.55391386e-04,
-0.00413512,  0.00035834, 0.0020628 , -6.68759784e-04,  0.00021038,  0.00061894,  0.00042819)   ('**CDI**', -0.00114877, -0.00328011,  8.50527467e-04,  0.00493075,  0.00462521, 0.00724026, -1.93383326e-04,  0.00061894,  0.00221491,  0.00196327)   ('**SELIC**', -0.00252005, -0.0007994 , -1.55863971e-03,  0.0184824 ,  0.00829757, 0.00776359,  1.87080325e-03,  0.00042819,  0.00196327,  0.00255616)]]
cs95
  • 379,657
  • 97
  • 704
  • 746
  • Is `df.cov().values` what you want? – pe-perry Feb 19 '19 at 03:50
  • Ow! I advanced. Thks. But there is a last problem, several values ​​are in the same cell, example: [8.28908536e-02 -1.17298206e-02 4.95575325e-02 -6.98939122e-02 -1.66098898e-02 1.54007623e-02 -1.53656407e-03 -4.87122159e-04 -1.14877409e-03 -2.52004638e-03] I need these values ​​to be separated. – Nicollas Gomes Feb 20 '19 at 00:42
  • They should be 'separated', please check `df.cov().values.shape`, it should be `(10, 10)` (10 variables) in your case. – pe-perry Feb 20 '19 at 03:54
  • It worked! Thank you very much. – Nicollas Gomes Feb 21 '19 at 00:00

0 Answers0