change column name to a different row in pandas

Viewed 40

I want to replace the column name to the header line in a pandas dataframe,

----------|columnB|
columnA|----------|

i want columnA and COlumnB in the first line(header) in the dataframe like
ColumnA|columnB|

as header how do i change this in a pandas dataframe?

1 Answers

If you want manual option. You can replace column name using:
df.rename({'----------': 'columnA'}, axis = 1) and then drop the row with the 'columnA' value.
If you want more advanced option, you need to probably loop each column check the header and if it's not good, then search for row with the desired header and set it as header.

Related