df = pd.DataFrame({'location': ['A', 'A', 'A', 'B', 'B', 'B'], 'dist_to_A':
    [0, 0, 0, 50, 50, 50], 'dist_to_B': [50, 50, 50, 0, 0, 0],
    'location_var': [10, 10, 10, 14, 14, 14], 'ind_var': [3, 8, 10, 1, 3, 4]})
df['ind'] = df.index
ind_to_loc = dict(df['location'])
loc_dict = dict(df.groupby('location').agg(lambda x: int(np.mean(x)))[
    'location_var'])
df.drop(['location_var', 'location'], axis=1, inplace=True)
df_long = pd.wide_to_long(df, ['dist_to_'], i='ind', j='location')
df_long['choice'] = df_long.index.map(lambda x: ind_to_loc[x[0]])
df_long['location_var'] = df_long.index.map(lambda x: loc_dict[x[1]])
print(df_long.sort())
Сложная (для меня) перестройка с широкой на длинную в Pandas