0

I've created a DataFrame and getting index in output. I'm unable to find a way to hide these index in the output.

def create_dataframe(k,v):
  
  a= pd.DataFrame(v, columns=k)       
  return a

k = ["Employee ID", "Name", "Salary"]
v = [["1446","Ashish", "80"],["1447","Priya", "70"], ["1448","Riya", "90"]]

create_dataframe(k,v)

Output:

    Employee ID Name    Salary
    0   1446    Ashish  80
    1   1447    Priya   70
    2   1448    Riya    90

I can use a.style.hide_index(), however, with that my DataFrame will be changed to a "Styler" object and I don't want that.

index=False doesn't work either.

Can someone please check to point the issue and explain by correcting the code?

Алексей Р
  • 7,507
  • 2
  • 7
  • 18
  • Does this answer your question? [How to print pandas DataFrame without index](https://stackoverflow.com/questions/24644656/how-to-print-pandas-dataframe-without-index) – Алексей Р Dec 07 '21 at 02:58
  • Not exactly, it talks about tabulating the DataFrame and/or using styler which I'm not planning to. I'm sure I'm missing something basic just not able to spot it – Ashish Gupta Dec 07 '21 at 03:03
  • try `df.to_string(index=False)` – sagar1025 Dec 07 '21 at 03:17
  • @sagar1025 It will covert my DataFrame to string don't want that to happen – Ashish Gupta Dec 07 '21 at 03:25
  • 1
    It might help to describe your use case. Why does it matter if the output is `Styler` / `to_string` / `to_html`? If you want the default dataframe css but without a visible index, you could set the index to empty strings: `df.set_axis([''] * len(df))` – tdy Dec 07 '21 at 03:43
  • 1
    what is the problem with index? pandas dataframes are index aligned. what do you intend to do without the index? – anky Dec 07 '21 at 04:31

0 Answers0