Reputation: 1395
I'm trying to merge the index with header name. My data frame is like
t = pd.DataFrame({'A': ['a', 'b']})
t
A
0 a
1 b
But the desired output is
A_0 A_1
0 a b
Upvotes: 3
Views: 170
Reputation: 75080
Try with unstack()
, then transpose , then join the multiindex columns:
final=t.unstack().to_frame().T
final.columns=['_'.join(map(str,i)) for i in final.columns]
print(final)
A_0 A_1
0 a b
Upvotes: 2