Pretty-print an entire Pandas Series / DataFrame

后端 未结 12 2196
再見小時候
再見小時候 2020-11-22 03:26

I work with Series and DataFrames on the terminal a lot. The default __repr__ for a Series returns a reduced sample, with some head and tail values, but the res

相关标签:
12条回答
  • 2020-11-22 03:56

    After importing pandas, as an alternative to using the context manager, set such options for displaying entire dataframes:

    pd.set_option('display.max_columns', None)  # or 1000
    pd.set_option('display.max_rows', None)  # or 1000
    pd.set_option('display.max_colwidth', -1)  # or 199
    

    For full list of useful options, see:

    pd.describe_option('display')
    
    0 讨论(0)
  • 2020-11-22 03:56

    If you are using Ipython Notebook (Jupyter). You can use HTML

    from IPython.core.display import HTML
    display(HTML(df.to_html()))
    
    0 讨论(0)
  • 2020-11-22 03:56

    datascroller was created in part to solve this problem. It loads the dataframe into a terminal view you can "scroll" with your mouse or arrow keys, kind of like an Excel workbook at the terminal that supports querying, highlighting, etc.

    import pandas as pd
    from datascroller import scroll
    
    # Call `scroll` with a Pandas DataFrame as the sole argument:
    my_df = pd.read_csv('<path to your csv>')
    scroll(my_df)
    
    0 讨论(0)
  • 2020-11-22 04:00

    Try using display() function. This would automatically use Horizontal and vertical scroll bars and with this you can display different datasets easily instead of using print().

    display(dataframe)
    

    display() supports proper alignment also.

    However if you want to make the dataset more beautiful you can check pd.option_context(). It has lot of options to clearly show the dataframe.

    Note - I am using Jupyter Notebooks.

    0 讨论(0)
  • 2020-11-22 04:01

    You can achieve this using below method. just pass the total no. of columns present in the DataFrame as arg to

    'display.max_columns'

    For eg :

    df= DataFrame(..)
    with pd.option_context('display.max_rows', None, 'display.max_columns', df.shape[1]):
        print(df)
    
    0 讨论(0)
  • 2020-11-22 04:03

    No need to hack settings. There is a simple way:

    print(df.to_string())
    
    0 讨论(0)
提交回复
热议问题