Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 649

Replacing Header with Top Row

$
0
0

I currently have a dataframe that looks like this:

       Unnamed: 1    Unnamed: 2   Unnamed: 3  Unnamed: 40   Sample Number  Group Number  Sample Name  Group Name1             1.0           1.0          s_1         g_12             2.0           1.0          s_2         g_13             3.0           1.0          s_3         g_14             4.0           2.0          s_4         g_2

I'm looking for a way to delete the header row and make the first row the new header row, so the new dataframe would look like this:

    Sample Number  Group Number  Sample Name  Group Name0             1.0           1.0          s_1         g_11             2.0           1.0          s_2         g_12             3.0           1.0          s_3         g_13             4.0           2.0          s_4         g_2

I've tried stuff along the lines of if 'Unnamed' in df.columns: then make the dataframe without the header

df.to_csv(newformat, header=False, index=False)

but I don't seem to be getting anywhere.


Viewing all articles
Browse latest Browse all 649

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>