joshijai2
joshijai2

Reputation: 167

How to display all the columns of dataframe without changing global printing option?

I want to view all the columns of my dataframe. It has 30 columns. While trying to view a specific row, it gets truncated.

I can change the global printing option pd.set_option('display.max_columns', None).

But I don't want to do that. I only want to view all the columns(data in the columns) once. Is there any way or workaround?

Upvotes: 2

Views: 1880

Answers (3)

foglerit
foglerit

Reputation: 8279

If you want to display the entire DataFrame, you can convert it to HTML and display it with IPython's HTML renderer:

import pandas as pd
from IPython.display import HTML

df = ...
HTML(df.to_html())

But note that if your DataFrame is large, this may cause the notebook to be unstable.

Upvotes: 2

Ralvi Isufaj
Ralvi Isufaj

Reputation: 482

Use option_context instead: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.option_context.html

You use it with a with statement:

with pd.option_context('display.max_columns', 30):
    #do your stuff

Upvotes: 2

k0rnik
k0rnik

Reputation: 502

You can change global printing options,

Method 1:

pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)

Method 2:

pd.options.display.max_columns = None
pd.options.display.max_rows = None

This question was already answered here: How to show all of columns name on pandas dataframe?

Credit to Yolo

Upvotes: -1

Related Questions