Pandas adding extra row to DataFrame when assigning index

后端 未结 1 1467
礼貌的吻别
礼貌的吻别 2020-12-31 20:02

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

I tried to set the index a few different ways. The first wa

相关标签:
1条回答
  • 2020-12-31 20:43

    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
    
    0 讨论(0)
提交回复
热议问题