How to print pandas DataFrame without index
To print a DataFrame without the index, swiftly apply the Panda's function to_string(index=False)
:
What was:
A B
1 4
2 5
3 6
Now index-less! A tidy table, just the data. Let's go further down this rabbit hole.
Beyond basic printing
Neatly hide index using style
Conjure a stylish dataframe in your Jupyter notebook with style.hide_index()
:
Now you have a clean slate to work with, impressing your colleagues and terrifying your enemies.
Time travel with datetime formatting
When dealing with time travelers (or the timestamp), extract and format time:
It's like your DataFrame took its sunglasses off and looked directly at the clock.
Exporting without index
Do you need the data elsewhere minus the index? One index=False
coming right up:
With sep
set, DataFrame breaks the language barrier and speaks CSV fluently.
Fancy console prints with tabulate
Welcome to the console-print renaissance. Dress up your DataFrame with tabulate
:
tablefmt
accessorizes the style, showindex=False
keeps things minimalistic.
Slicing and dicing data
Carve up the DataFrame, like a master sushi chef:
Fancy HTML display
To paint an HTML-worthy picture:
This puts the DataFrame in an HTML tuxedo; it's Oscar-ready now.
Visual aid
Let's make it visual with everyone's favorite – emojis. Here's what we've achieved:
Turns into:
With to_string(index=False)
, Index checks out from Airbnb(DataFrame)
.
Was this article helpful?