9

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

I tried to set the index a few different ways. The first was using index_col=0 in the DataFrame creation. I also tried DF_mutations.index = DF_mutations["Gene.name"] but they both led to an empty row underneath the header show below: enter image description here

How can I get rid of this extra row when I'm reassigning the index values?

3
  • So you do not want a name for the index? The empty row is because of the index's name Commented Oct 14, 2015 at 5:13
  • The name isn't necessary, I can do away with it. How can you drop the index name once you reassign it? Commented Oct 14, 2015 at 5:15
  • I don't think there is actually an empty row in the DataFrame itself. There is just an empty row in the display. You don't need to get rid of the name unless you actually care about that visual display. Commented Oct 14, 2015 at 5:20

1 Answer 1

14

The empty row in the print you see is because the index has a name - Gene.name (This is not a real row in the DataFrame though) . If you don't want that row , I believe you would need to do away with the 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.