displaying Pandas DataFrame in HTML without the extra row

后端 未结 2 1999
后悔当初
后悔当初 2021-01-13 21:13

If I use DataFrame.set_index, I get this result:

import pandas as pd

df = pd.DataFrame([[\'foo\',1,3.0],[\'bar\',2,2.9],
                   [\'         


        
2条回答
  •  不知归路
    2021-01-13 21:38

    I poked around in the source for Styler and figured it out; if you set df.index.names = [None] then this suppresses the "extra" row (along with the column header that I don't really care about):

    import pandas as pd
    
    df = pd.DataFrame([['foo',1,3.0],['bar',2,2.9],
                       ['baz',4,2.85],['quux',3,2.82]],
                     columns=['name','order','gpa'])
    df = df.set_index('name')
    df.index.names = [None]
    df
    

提交回复
热议问题