I have a dataframe like this:
data = {'col1':['XXX', 'AAA', 'ZZZ'],'col2':['BBB', 'AAA','TTT'], 'col3': ['BBB', 'CCC', 'TTT'], 'col4': ['XXX', 'CCC', 'ZZZ']}
df = pd.DataFrame(data)
df
And I want to produce a column that joins the strings together, but without automatically alphabetising it:
I want it to use col1 as the first portion of the combo.
However, I have run this code, and am getting an output that prioritises the alphabetical order - which I don't want. I want it to use the order stipulated in the code
df['combos'] = ["_".join((k for k in set(v) if pd.notnull(k))) for v in
df[["col1", "col2", "col3", "col4"]].values]
df