Regarding Pandas - can you take a row and turn it into a column?

Say I had two dataframes and they looked like this;


0 5


tag1 tag2 tag3 tag4 tag5
0 5 6 7 8 9

Is there a way to combine these so to end up with a dataframe that looks like this;

id tag
0 5 5
1 5 6
2 5 7
3 5 8
4 5 9



This is pretty close, still working on it.

df3 = df2.T.reset_index().drop([“index”], axis=1)
df4 = df3[‘id’] = id[‘id’].loc[0]

I need to find a way to do double inserts now, but that is a different issue. Thanks again.

Google has many references at Stack Overflow for converting rows to columns. Maybe one or more of them will help.

P.S. df1 has additional rows in the desired output. Were these in df1 from the start or were they added programatically?

Those are indexes on the left. Note - no column heading. I Googled before and after posting. See edit in original post. A lot of people post, not because they don’t Google the problem. But rather, they are hedging by searching and posting. Posting here may get me a more formal / proper solution than Googling. Having someone actually respond gives me more insight and explanation. It also increases my chances of finding an answer as I Google.


I’ve only used Pandas once for a time series analysis, so have no experience with its ‘Excel-like’ functions. However, this seems fairly straightforward as an operation in Pandas.

It seems likely that one of the first few S.O. results will do the trick. If you find one, please paste the link to it here for future searches.