Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to print Dataframe in Python without Index?

  • Last Updated : 13 Sep, 2021

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 DATAFRAME  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:")
display(df)
print()
 
print("THIS IS THE DATAFRAME  WITHOUT INDEX VAL")
print(df.to_string(index=False))

Output:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!