I would like to merge two binary columns in one, taking max value. I found similar questions, but I would like to ask if there is a chance to find a solution when you don't know the names of your columns (so it could be in a generic loop) .
for key, value in duplicates_binary_questions.items():
value = [str(x) for x in value]
sub_data_binary = data[
data.columns[np.isin([x[: x.find("_")] for x in data.columns], value)]
]
duplicates_binary_questions = { "question" : [114, 155] }
I have a dictionary with ids (value) of duplicated questions (key). I'm creating an object (sub_data_binary) which are ids of duplicated questions from dictionary aligned with my main data (where I have all questions). What I want to do is to join/melt two binary columns (where columns can have different names) into one, taking the max value (join columns within sub_data_binary).
I would appreciate for any suggestions :)
EDIT: I' ve found a solution - I've used sub_data_binary.max(axis=1) - I did try to use it before asking this question, but I had an error - It turned out that I didn't rename sub_data_binary, so then I had a problem to merge it with my main dataframe :D