import pandas as pd
import numpy as np
# создаю твои датафреймы
data1 = [[25.0, 0.0],
[27.0, 3.0],
[26.0, 0.0],
[13.0, 0.0],
[43.0, 1.0]]
data2 = [[13.0, 0.078963],
[25.0, 0.052023],
[26.0, 0.066743],
[5.0, 0.103289],
[6.0, 0.151293]]
columns = ['total_acc', 'mort_acc']
df1 = pd.DataFrame(np.array(data1), columns=columns)
df2 = pd.DataFrame(np.array(data2), columns=columns)
# создаю новую колонку mort_acc и заменяю старую в df1 на новую
def get_mort(_line):
total, mort = _line[1]
if not mort:
mort = float(df2.mort_acc[df2.total_acc == total])
return mort
new_mort = list()
for line in df1.iterrows():
new_mort.append(get_mort(line))
df1.mort_acc = new_mort