pandas pd.options.display.max_rows not working as expected

ghz 7months ago ⋅ 143 views

I’m using pandas 0.25.1 in Jupyter Lab and the maximum number of rows I can display is 10, regardless of what pd.options.display.max_rows is set to.

However, if pd.options.display.max_rows is set to less than 10 it takes effect and if pd.options.display.max_rows = None then all rows show.

Any idea how I can get a pd.options.display.max_rows of more than 10 to take effect?

Answers

This issue could be related to the display settings in Jupyter Lab. By default, Jupyter Lab may limit the number of rows displayed in a DataFrame output to improve performance and prevent overwhelming the browser with large outputs.

To change the maximum number of rows displayed in a DataFrame output in Jupyter Lab, you can try the following steps:

  1. Check Notebook Settings: Make sure you are setting the pd.options.display.max_rows value in the same notebook where you are running your code. Sometimes, changes to display settings may not take effect if set in a different notebook or cell.

  2. Reset Display Options: Before setting max_rows, you can reset all display options to their default values using pd.reset_option("all"). Then, set max_rows to the desired value.

    import pandas as pd
    
    # Reset all display options to default values
    pd.reset_option("all")
    
    # Set max_rows to a value greater than 10
    pd.options.display.max_rows = 20  # Example: Set to 20 rows
    
  3. Use pd.set_option(): Instead of directly assigning a value to pd.options.display.max_rows, try using pd.set_option():

    import pandas as pd
    
    # Set max_rows using pd.set_option()
    pd.set_option('display.max_rows', 20)  # Example: Set to 20 rows
    
  4. Check Jupyter Lab Settings: Verify that there are no specific settings in Jupyter Lab itself that limit the number of displayed rows. You can check the Jupyter Lab settings menu to see if there are any options related to output display limits.

  5. Restart Kernel: Sometimes, changes to display options may require restarting the kernel for them to take effect. Try restarting the kernel and then executing your code again.

  6. Upgrade Pandas: Ensure you are using the latest version of pandas. There might be bug fixes or improvements related to display options in newer versions. You can upgrade pandas using pip:

    pip install --upgrade pandas
    

By following these steps, you should be able to set pd.options.display.max_rows to a value greater than 10 and have it take effect in Jupyter Lab. If the issue persists, it might be helpful to check the Jupyter Lab documentation or seek assistance from the Jupyter Lab community.