Рассмотрим следующий MWE:
Код: Выделить всё
# Parameter
lo = -5
hi = 5
n = 4
idx = range(n)
rep = 2
# DF 1
idx_1 = np.tile(idx, rep)
data_1 = np.random.randint(lo, hi, n*rep)
df_1 = pd.DataFrame(data_1, index=idx_1, columns=['column'])
# DF 2
idx_2 = idx
col_2 = range(lo, hi+1)
data_2 = np.random.rand(n, len(col_2))
df_2 = pd.DataFrame(data_2, index=idx_2, columns=col_2)
# Result
result = df_2.lookup(df_1.index, df_1.column)
Панда мне говорит:
Код: Выделить всё
FutureWarning: The 'lookup' method is deprecated and will beremoved in a future version.You can use DataFrame.melt and DataFrame.locas a substitute.
Интуитивным, но довольно неэффективным решением было бы
Код: Выделить всё
result = [df_2.loc[df_1.index[i], df_1.iloc[i, 0]] for i in range(n*rep)]
Подробнее здесь: https://stackoverflow.com/questions/711 ... kuprow-col