I am using pandas to try to replace each "Y" value in the "Option" columns with the Options Name (e.g. the column header)
Below is the expected output, but I cannot figure out how to write the loop to replace values with the column header.
I am using pandas to try to replace each "Y" value in the "Option" columns with the Options Name (e.g. the column header)
Below is the expected output, but I cannot figure out how to write the loop to replace values with the column header.
try this:
for column in dataframe.columns:
dataframe.loc[dataframe[column]=='Y', column] = column
you're basically iterating over the columns and replacing cells that have a 'Y' with its column name. btw, 'column' above is just an arbitrary name: it could be 'x' and it work all the same.