import pandas as pd
data = [[1, 1, 2, 1, 0], [ 2, 2, 2, 1, 4], [ 3, 1, 0, 1,4], [ 4, 1, 3, 1, 4],
[5, 1, 6, 1, 4], [ 6, 1, 2, 0, 4], [ 7, 1, 2, 7,4], [ 8, 1, 2, 1, 1],
[9, 1, 2, 1, 2], [10, 1, 2, 1, 3], [11, 1, 2, 1,5], [12, 1, 2, 1, 6]]
df = pd.DataFrame(data, columns=['Id','c1', 'c2','c3', 'c4'])
import scipy.integrate
import scipy.special
mat = scipy.spatial.distance.cdist(
df[['c1','c2','c3','c4']],
df[['c1','c2','c3','c4']],
metric='euclidean'
)
new_df = pd.DataFrame(mat, index=df['Id'], columns=df['Id'])
When I apply sorting in dataframe, it works:
new_df.sort_values(by=1,ascending=True,kind="mergesort",axis=1)
but if I apply sorting in a subset of dataframe it does not work:
i = 1
j = 2
new_dff = new_df[i:j]
new_dff.sort_values(by=1, ascending=True, kind="mergesort", axis=1)