Pandas adding an extra row to a DataFrame when assigning an index

I am trying to use the 0th column ("Gene.name") as index values. Here's the raw data below: enter image description here

I tried to set the index in several ways. The first used index_col=0 in creating the DataFrame . I also tried DF_mutations.index = DF_mutations["Gene.name"] , but both of them led to an empty line under the heading below: enter image description here

How can I get rid of this extra line when I redefine index values?

+5
source share
1 answer

The empty line in the printout that you see is that index has a name - Gene.name (however, this is not a real line in the DataFrame). If you do not want this line, I believe that you will need to end this name. Example -

 df.index.name = None 

Demo -

 In [6]: df = pd.DataFrame([[1,2,3,4],[1,2,3,4]]).set_index(0) In [7]: df Out[7]: 1 2 3 0 <-------------------------- Name of the index for this DataFrame 1 2 3 4 1 2 3 4 In [10]: df.index.name=None In [11]: df Out[11]: 1 2 3 1 2 3 4 1 2 3 4 
+12
source

Source: https://habr.com/ru/post/1233675/


All Articles