Home > other >  How to square-form a dataframe with pair index
How to square-form a dataframe with pair index

Time:05-03

I have a JSON data like:

a={('A', 'B'): 0.8333333333333334, ('A', 'C'): 0.5, ('B', 'C'): 0.625}

I need to draw a heatmap based on that data set. but the dataframe I obtained by

df=pd.DataFrame(a,index=['value']).T.reset_index()

is like:

enter image description here

and this seems can not be used to draw a heat map. And the result dataframe should be looked like this:

df=pd.DataFrame({'A':{'A':1,'B':0.83333,'C':0.5},'B':{'A':0.83333,'B':1,'C':0.625},'C':{'A':0.5,'B':0.625,'C':1}})

enter image description here

CodePudding user response:

Assuming:

a = {('A', 'B'): 0.8333333333333334, ('A', 'C'): 0.5, ('B', 'C'): 0.625}

you can convert to Series and heatmap

  • Related