skip to Main Content

I’m trying to print a pandas dataframe in a cell of a Jupyter Notebook. However, for some reason, the DataFrame is truncated at some point of the line and continues above. Any clue of how to increase the number of characters printed per line in the output?

Print of notebook output

More info:

  • The limit of characters also affects Debug Console. When trying to print the DataFrame in Debug Console, the same behaviour occurs.

  • I’m using the function print() to print the DataFrame

  • I’ve tried to change pandas options without success:

pd.set_option('display.max_columns', None)  
pd.set_option('display.width', None)
  • I’ve tried this solution here. Didn’t work.

2

Answers


  1. try adding also with the max rows settings:

    pd.set_option('display.max_rows', None)
    pd.set_option('display.max_columns', None)
    pd.set_option('display.expand_frame_repr', False)
    
    Login or Signup to reply.
  2. The option you are looking for here is display.width, which is set to 80 by default. By adding pd.set_option('display.width', None), you can disable this limit.

    So, for this example DataFrame:

    columns = [f'---------Column{i}' for i in range(1, 7)]
    data = {col: [random.random() for _ in range(2)] for col in columns}
    df = pd.DataFrame(data)
    

    Before setting the pd.set_option('display.width', None):

    print(df)
    
    
       ---------Column1  ---------Column2  ---------Column3  ---------Column4  
    0          0.661599          0.700977          0.252833          0.899251   
    1          0.864813          0.588307          0.161888          0.051829   
    
       ---------Column5  ---------Column6  
    0          0.271721          0.067461  
    1          0.016571          0.347471  
    

    And after:

    pd.set_option('display.width', None)
    print(df)
    
    
       ---------Column1  ---------Column2  ---------Column3  ---------Column4  ---------Column5  ---------Column6
    0          0.165949          0.351962          0.288048          0.970479          0.461898          0.222051
    1          0.128192          0.070330          0.141980          0.555047          0.965609          0.734030
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search