def rename_x(df):
    for col in df:
        if col.endswith('_x'):
            df.rename(columns={col: col.rstrip('_x')}, inplace=True)
rename_x(merged)
Merging two pandas dataframes results in "duplicate" columns