I have a matrix on the following form (not necessarily square):
A B C D
A 0 0.2 0.3 0.5
E 0.2 0.6 0.9 0.2
D 0.5 0.3 0.6 0
F 0.1 0.4 0.5 0.3
And I would like to turn it into a square matrix as follows
A B C D E F
A 0 0.2 0.3 0.5 0.2 0.1
B 0.2 0 0 0.3 0.6 0.4
C 0.3 0 0 0.6 0.9 0.5
D 0.5 0.3 0.6 0 0.2 0.3
E 0.2 0.6 0.9 0.2 0 0
F 0.1 0.4 0.5 0.3 0 0
In other words, I would like to expand both rows and columns so that it is a symmetric square matrix (rows and columns are in the same order) and missing values are filled with 0.
I guessed there should be a way to do this easily/efficiently using built in functions of pandas but I am not familiar with the package.
for convenience:
df = pd.DataFrame([[0, 0.2, 0.3, 0.5],
[0.2, 0.6, 0.9, 0.2],
[0.5, 0.3, 0.6, 0],
[0.1, 0.4, 0.5, 0.3]],
index=['A', 'E', 'D', 'F'],
columns=['A', 'B', 'C', 'D'])