cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Notebook Visualisations suddenly not working

117074
New Contributor III

Hi all,

I have a python script which runs SQL code against our Delta Live Tables and returns a pandas dataframe. I do this multiple times and then use 'display(pandas_dataframe)'. Once this displays I then create a visualization from the UI which is then added to a dashboard.

I've run this script many times with no issues, however in the past 2 hours the behaviour of the notebook seems to have changed. When I run 'display(pandas_dataframe)' it no longer returns in a state that visualisations can be run from it. Instead it returns as if I'm using the print(pandas_dataframe) instead.

Any advice would be great, thank you. 

 

More info'

Using databricks at works through my company cloud set-up. AWS cloud.

3 REPLIES 3

117074
New Contributor III

Update: Upon restarting the cluster the problem seems to have resolved. However, I still need to find out an explanation for why this happened as it has caused additional work to now be done to restore the graphs.

Kaniz_Fatma
Community Manager
Community Manager

Hi @117074It sounds like youโ€™re encountering an unexpected behaviour in your Databricks Notebook when using display(pandas_dataframe) it to visualize your data.

Letโ€™s explore some potential solutions:

  1. Check Your Imports:

    • Ensure that you have the necessary imports at the beginning of your notebook. Specifically, make sure youโ€™ve imported pandas and any other relevant libraries for visualization (e.g., matplotlib, seaborn, etc.).
  2. Matplotlib Show():

    • When using display(pandas_dataframe), it relies on the underlying visualization libraries (such as Matplotlib) to render the plots. Sometimes, the plots may not display immediately.
    • After calling display(pandas_dataframe), try adding plt.show() (assuming youโ€™ve imported matplotlib.pyplot as plt) to explicitly show the plot. This can help ensure that the visualization is rendered properly.
  3. Check for Errors or Warnings:

    • Look for any error messages or warnings in your notebook. These can provide clues about what might be going wrong.
    • Check the Databricks logs or console for any relevant information.
  4. Kernel Restart:

    • Sometimes, notebook kernels can get into a state where they donโ€™t display plots correctly. Try restarting the kernel and running your code again.
    • You can restart the kernel by clicking on the โ€œRestartโ€ button in the Databricks notebook toolbar.
  5. Inspect the Dataframe:

    • Before calling display(pandas_dataframe), verify that your Pandas dataframe (pandas_dataframe) contains the expected data.
    • Print a few rows of the dataframe using print(pandas_dataframe.head()) to ensure that the data is loaded correctly.
  6. Check Dashboard Configuration:

    • If youโ€™re adding the visualization to a dashboard, ensure that the configuration settings (such as chart type, axes, etc.) are correctly set up.
    • Double-check any filters or parameters that might affect the visualization.
  7. Cache and Materialization:

    • Databricks caches dataframes by default. If youโ€™re re-running the same script multiple times, itโ€™s possible that cached data is affecting the results.
    • Consider using .cache() or .materialize() on your dataframe to control caching behavior.
  8. Update Databricks Runtime:

    • Sometimes issues can arise due to the Databricks runtime version. Check if there have been any recent updates or changes to the runtime.
    • Consider updating to the latest stable version if youโ€™re not already using it.

If none of these solutions works, consider reaching out for further assistance. Good luck! ๐Ÿš€

 

117074
New Contributor III

Thank you for the detailed response Kaniz, I appreciate it! I do think it may have been cache issues due to there being no spark computation when running them when the error occured.

It did lead me down a train of thought.. is it possible to extract the code used to generate the graphs from the visualisation UI? That way instead of doing display(pandas_df) and manually making the visualisations myself - I can just take this code. Alternatively, I may look into using some plotly graphs! 

Thank you

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group