问题
How to convert pair lists (to matrix) to heat map?
Say, I have a Dataframe (pandas) like following ...
a x 0.63
a y 1.00
a z 0.22
b z 0.13
b x 0.20
b y 0.58
c y 0.21
c z 0.14
I want to generate heat map for this data.
do I need to convert it into matrix (& how?) like following...
x y z
a 0.63 1.00 0.22
b 0.20 0.58 0.13
c 0.00 0.21 0.14
回答1:
Something like the following would work, your df didn't have column names but I set them to be 'a','b','c' respectively:
In [20]:
df.pivot(index='a',columns='b').fillna(0)
Out[20]:
c
b x y z
a
a 0.63 1.00 0.22
b 0.20 0.58 0.13
c 0.00 0.21 0.14
来源:https://stackoverflow.com/questions/29115909/how-to-convert-pair-lists-to-matrix-to-heat-map-python