Skip to content
Advertisement

Removing index from pandas data frame on print

I’m really struggling to get this to print the way I want to. I’ve read through the documentation on removing index, but it seems like it still shows up. Here is my code:

JavaScript

The text file isn’t anything special, looks like this:

JavaScript

The output of this looks like this:

JavaScript

How do I get rid of those random 0s?

Advertisement

Answer

The 0 on top is your column name, since you don’t have one…

The 0 on the left is your index, something that absolutely every dataframe needs.

If you really want to see things without those essential pieces, you can use

print(df.to_string(header=False, index=False))

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement