Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to plot the dataframe in form of matrix?

I have a dataframes containing few columns, however I already calculated the value of it,
df:

    age     size    gender   time
 1  0.0     3.433    3.454    2.165
 2  3.654   0.0      5.0      4.88
 3  6.43    1.33     0.0      3.56
 4  2.33    8.3      1.2      0.0

These are calculated values, so how can i show or plot it in the form of matrix such that:
Expected output:

      age     size    gender   time
age   0.0     3.654   6.43    2.33
size  3.433    0.0    1.33    8.3
gender 3.454   5.0    0.0     1.2
time   2.165   4.88   3.56    0.0,

I tried transpose but it didnot work, Thank you in advance

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to rename the index then transpose the data:

df.reset_index(drop=True).rename(index=dict(enumerate(df.columns))).T


          age   size    gender  time
age     0.000   3.654   6.43    2.33
size    3.433   0.000   1.33    8.30
gender  3.454   5.000   0.00    1.20
time    2.165   4.880   3.56    0.00
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading