Q: Replace values in Pandas DataFrame with value based on headers I have this Pandas DataFrame
Index 1  2  3  4  5
    0 1  1  0  0  0

I want to replace it:
Index 1     2
    0 pos1  pos2

I have seen a similar question but use "ix", deprecated solutions or only replace values with headers

A: One option is to use replace and add_prefix:
df.replace({k: 1 for k in df.columns}, 
           {k: v for k, v in zip(df.columns, df.add_prefix('pos').columns.values)})

Alternately, you can use apply and replace 1 values with pos + .name property of that entry (which is equivalent to the column name in this case):
df.apply(lambda row: [f"pos{row.name}" if x == 1 else x for x in row], axis=0)

Output (for both approaches):
          1     2  3  4  5
Index                     
0      pos1  pos2  0  0  0

Data:
df = pd.DataFrame([{'1': 1, '2': 1, '3': 0, '4': 0, '5': 0}]).rename_axis('Index')

