I am trying to merge multiple columns within a csv into a single column with each original column's header being repeated as shown below.
userA userB
A1 B1
A2 B2
A2 B3
A2 B4
Into this:
userA A1
userA A2
userA A3
userA A4
userB B1
userB B2
userB B3
userB B4
Does anyone have any suggestions on how to do this. I do have some experience in pandas but I'm currently at a loss.
UPDATE: I found how to merge the columns
df = pd.read_csv(filename, sep='\t')
df = df.combine_first(pd.Series(df.values.ravel('F')).to_frame('merged'))
FINAL UPDATE: Solved using melt()
df = pd.melt(df)
df.stack().reset_index(level=1)