I've a dataframe df as follows such that it's the number of columns vary time to time:
Column 1 Column 2
0 A E
1 B F
2 C G
3 D H
I need to combine the columns into one such that it looks like as given below:
column 3
0 A,E
1 B,F
2 C,G
3 D,H
For rows to combine into one the following is the code. I need something like that which will not specify the column names.
df = df.stack().to_frame().T
df.columns = ['{}_{}'.format(*c) for c in df.columns]