Reputation: 7
I would like to make the data frame df symmetrical based on the upper numbers. As can be seen in the example in the picture. [Example]
Any ideas how could this be done most efficiently?
Upvotes: 0
Views: 29
Reputation: 7863
You can try the following:
import numpy as np
arr = df.to_numpy()
out = pd.DataFrame(np.triu(arr, 0) + np.triu(arr, 1).T)
Upvotes: 1