i have a table in pandas that looks like this:
0 | A | Another |
---|---|---|
1 | header | header |
2 | First | row |
3 | Second | row |
and what i would like to have a table like this :
0 | A header | Another header |
---|---|---|
1 | First | row |
2 | Second | row |
how can i merge cells 0 and 1 to one header column?
CodePudding user response:
There is a question about that column '0'
, if indeed it is one. But if it is not (and is just the index having been pasted slightly incorrectly), then I would do:
newdf = df.iloc[1:].set_axis(df.columns ' ' df.iloc[0], axis=1)
>>> newdf
A header Another header
1 First row
2 Second row