Reputation: 1553
Here's the thing, I need to put one row from other dataframe to the top of main dataframe in pandas, above first row where are columns named.
Sample :
1value 2value 3value 4value 5value
acity 4 3 6 2 6
bcity 2 6 6 4 1
ccity 5 11 53 6 3
dcity 5 1 4 6 3
gcity 6 4 2 7 4
And the other sample:
1value 2value 3value 4value 5value
2 5 2 6 3
And now I need to add value of second sample to the top of first sample. Desired output:
2 5 2 6 3
1value 2value 3value 4value 5value
acity 4 3 6 2 6
bcity 2 6 6 4 1
ccity 5 11 53 6 3
dcity 5 1 4 6 3
gcity 6 4 2 7 4
And just for mention, I have about 3000 rows, and 250 columns in this Sample dataframe.
I don't have any code yet, I tried to find here something...
Upvotes: 0
Views: 1219
Reputation: 214987
Not sure if this is what you need, but a multi index data frame looks like the output:
df1 or second sample:
df or the first sample:
Rename the columns with a multi-index columns:
df.columns = pd.MultiIndex.from_arrays([df1.values[0], df.columns])
Upvotes: 1