Skip to content
Related Articles

Related Articles

How to print Dataframe in Python without Index?
  • Last Updated : 24 Jan, 2021
GeeksforGeeks - Summer Carnival Banner

Prerequisites: Pandas

When printing a dataframe, by default, index appears with the output but this can be removed if required. To print the dataframe without indices index parameter in to_string() must be set to False.

Syntax: 

df.to_string(index = False)

Approach:



  • Import module
  • Create a simple dataframe .
  • Set index to false in to_string()
  • Print result

Implementation using this approach is given below

Example 1: 

Python3




import pandas as pd
  
df = pd.DataFrame({"Name": ["sachin", "sujay", "Amara", "shivam"
                            "Manoj"],
  
                   "Stream": ["Humanities", "Science", "Science"
                              "Commerce", "Humanities"]},
  
                  index=["A", "B", "C", "D", "E"])
  
print("THIS IS THE ORIGINAL DATAFRAME:")
display(df)
print()
  
print("THIS IS THE DATAFRMAE  WITHOUT INDEX VAL")
print(df.to_string(index=False))

Output:

Example 2:   

Python3




import pandas as pd
  
df = pd.DataFrame(["Geeks", "for", "geek"],
  
                  index=["A", "B", "C"])
  
print("THIS IS THE ORIGINAL DATAFRAME:")
dislay(df)
print()
  
print("THIS IS THE DATAFRMAE  WITHOUT INDEX VAL")
print(df.to_string(index=False))

Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :