2

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?

joshijai2
  • 157
  • 1
  • 11

3 Answers3

2

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
Ralvi Isufaj
  • 442
  • 2
  • 9
  • Thanks a lot. This works fine. Just add that we need to use `print(df.head())`, `df.head()` doesn't display anything. – joshijai2 Apr 25 '20 at 16:47
2

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.

foglerit
  • 7,792
  • 8
  • 44
  • 64
-1

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

k0rnik
  • 472
  • 5
  • 13
  • I mentioned without "pd.set_option('display.max_columns', None)". – joshijai2 Apr 25 '20 at 16:39
  • Apologies, I see the issue. Can you tell me where do you display those columns? Are you using Jupyter Notebook or IDE? Bear in mind that you can also set maximum columns without using max_colwidth (you can also set it to None to prevent folding) – k0rnik Apr 25 '20 at 16:46
  • I am using Jupyter Notebook. I don't want to change maximum columns for the entire notebook. I just want to view the data of specific rows once. Btw @ralvi-isufaj already found out a solution. – joshijai2 Apr 26 '20 at 06:08