def update_vals(row, data=data):
    if row.filename == data['filename']:
        row.n = data['n']
return row
df.apply(update_vals, axis=1)
How to update values in a specific row in a Python Pandas DataFrame?