Search code examples
pythonpandas

Adjust console width to print the whole Pandas dataframe


When printing to the console in Python I get output like:

                   Körpergrösse (cm)  ...  Motivation (1-10) 
Körpergrösse (cm)           1.000000  ...           0.226576 
Schuhgrösse                 0.710021  ...           0.096692 
Alter (Jahre)              -0.206736  ...           0.203746 
Motivation (1-10)           0.226576  ...           1.000000
    
[4 rows x 4 columns]

This is a pity because in my console there is more than enough space to print a lot more. (In this example the whole 4 x 4 correlation matrix..)


How can I make my console print the 'whole thing'? For example, by adjusting the console width? Or if that's not possible by doing some workaround before/while printing?


Solution

  • Assuming you are using pandas you can use these settings:

    import pandas as pd
    
    pd.set_option('display.max_rows', None)
    pd.set_option('display.max_columns', None)
    pd.set_option('display.width', None)
    
    print(df)
    

    the last option is to ensure it fits the console width