4

I am trying to remove index while converting pandas data-frame into html table. Prototype is as follows:

import pandas as pd
import numpy as np
df= pd.DataFrame({'list':np.random.rand(100)})
html_table = df.to_html()

In html table I don't want to display index.

5
  • 1
    Can you add data sample and desired output? Commented Oct 11, 2017 at 9:16
  • Please have a look at image available in the link. Commented Oct 11, 2017 at 9:18
  • 2
    don't post a link to an image, we require raw data and your code to reproduce your df correctly. Commented Oct 11, 2017 at 9:25
  • Sorry, I think how to provide a great pandas example Commented Oct 11, 2017 at 10:08
  • @jezrael sure, Editing for same. Commented Oct 11, 2017 at 10:15

2 Answers 2

9

Try this:

html_table = df.to_html(index = False)
Sign up to request clarification or add additional context in comments.

Comments

4

It seems you need remove index name:

df = df.rename_axis(None)

Or:

df.index.name = None

For not display index use:

print (df.to_string(index=False))

8 Comments

Yes that removes the index name but not 'index column' as I found(from Stack-overflow ) that it is not possible to remove index from Dataframe but column can be used as index but I need the column that can be used as index in the same level of other columns.
@arshpreet - I really dont understand - what is desired output? Do you need index name and only remove empty row? I think it is not possible.
But you can use df.columns.name='a' and df.index.name = None - it looks nice, but after df = df.reset_index() get column called index
that means we simple can't remove index column from Pandas DataFrame and also can't make 'index column name' in same row as oher columns exist?
You need always some index in pandas dataframe. You cannot remove it, only reaasign to default df.reset_index(drop=True) or set to another column.
|

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.