How do I expand the output display to see more columns of a pandas DataFrame?

后端 未结 19 1611
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 00:37

Is there a way to widen the display of output in either interactive or script-execution mode?

Specifically, I am using the describe() function on a pand

相关标签:
19条回答
  • 2020-11-22 00:53

    If you want to set options temporarily to display one large DataFrame, you can use option_context:

    with pd.option_context('display.max_rows', None, 'display.max_columns', None):
        print (df)
    

    Option values are restored automatically when you exit the with block.

    0 讨论(0)
  • 2020-11-22 00:53

    You can simply do the following steps,

    • You can change the options for pandas max_columns feature as follows

      import pandas as pd
      pd.options.display.max_columns = 10
      

      (this allows 10 columns to display, you can change this as you need)

    • Like that you can change the number of rows as you need to display as follows (if you need to change maximum rows as well)

      pd.options.display.max_rows = 999
      

      (this allows to print 999 rows at a time)

    Please kindly refer the doc to change different options/settings for pandas

    0 讨论(0)
  • 2020-11-22 00:55

    You can use this custom function for displaying things for pandas Dataframe.

    def display_all(df):     # for any Dataframe df
       with pd.option_context('display.max_rows',1000): # change number of rows accordingly
          with pd.option_context('display.max_columns',1000): # change number of columns accordingly
              display(df)
    

    display_all(df.head()) # pass this function to your dataframe and Voila!

    You don't have use pd.set_option for whole notebook just use for single cell.

    0 讨论(0)
  • 2020-11-22 00:59

    Set column max width using:

    pd.set_option('max_colwidth', 800)
    

    This particular statement sets max width to 800px, per column.

    0 讨论(0)
  • 2020-11-22 00:59

    If you don't want to mess with your display options and you just want to see this one particular list of columns without expanding out every dataframe you view, you could try:

    df.columns.values
    
    0 讨论(0)
  • 2020-11-22 01:01

    You can use print df.describe().to_string() to force it to show the whole table. (You can use to_string() like this for any DataFrame. The result of describe is just a DataFrame itself.)

    The 8 is the number of rows in the DataFrame holding the "description" (because describe computes 8 statistics, min, max, mean, etc.).

    0 讨论(0)
提交回复
热议问题