Home > Blockchain >  How to plot the dataframe in form of matrix?
How to plot the dataframe in form of matrix?

Time:10-06

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

CodePudding user response:

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
  • Related