Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Python

Printing DataFrame without an Index in Pandas

  • 08 Jan, 2025
  • Com 0
Featured Image of Printing DataFrame without an Index in Pandas

To print Pandas DataFrame without an index, you need to convert DataFrame into a String using the df.to_string() method and pass the “index=False” argument. Here, df means DataFrame.

The “index=False” argument specifies that the row index should not be included in the output.

Printing with index

import pandas as pd

data = {'Column1': [1, 2, 3], 'Column2': [4, 5, 6]}

df = pd.DataFrame(data)

print(df)

Output

Printing normal DataFrame

Printing without index

Instead of just writing print(df), we can use print(df.to_string(index=False)) syntax.

import pandas as pd

data = {'Column1': [1, 2, 3], 'Column2': [4, 5, 6]}

df = pd.DataFrame(data)

print(df.to_string(index=False))

Output

Printing DataFrame without Index in Pandas

You can see that only column names and values have been printed from the above output image.

Using the style.hide_index() Method

The df.style.hide_index() method returns a styled representation of a DataFrame without the index column.

Please ensure that you run the below code in an Interactive environment like JupyterLab or online notebooks.

import pandas as pd

data = {'Column1': [1, 2, 3], 'Column2': [4, 5, 6]}

df = pd.DataFrame(data)

# Create a styled representation of the DataFrame without index
styled_df = df.style.hide()

# Print the styled DataFrame
styled_df

Output

Output of using df.style.hide_index() method

You can see that the above DataFrame is without an index. Here, we don’t have to convert it into a string.

Why do we need to print without row index?

  1. It will help us read the better data without so much “clutter”.
  2.  Omitting indices can save space and reduce file sizes.
  3. By controlling the display, you can tailor the output to our specific needs.
Post Views: 17
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

Converting Columns to String in Pandas DataFrame
How to Remove Spaces from Column Names in Pandas DataFrame

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend