Pandas replace column values by condition with averages based on a value in another column
Get a dictionary with average age where experience &lt; age

mapping = df[df['age']&gt;df['experience']].groupby('age').mean().apply(list).to_dict()['experience']


Use this dictionary to replace values where experience &gt; age

df.loc[df['age']&lt;df['experience'],'experience'] = df[df['age']&lt;df['experience']]['age'].map(mapping)