cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
Sometimes when using python code, there will be cases when no data is returned. To account for this in python if you can first check if the dataframe has empty rows with.
if df.size == 0:
  (then run all of my actual code)
else:
  (run code to show error message)
With python matplotlib charts, this can be accomplished as follow:
# SQL output is imported as a pandas dataframe variable called "df"
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# Output: matplot ax.text object

fig, ax = plt.subplots(figsize = (8,3))
fig.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)
ax.axis('off')


# Function that defines the matplotlib object
def actual_text():
  string = df.iloc[0,0]
  ax.text(y = 0.7,
          x = 0.5,
          s = str(df.iloc[0,0]),
          horizontalalignment='center',
          verticalalignment='center',
          fontsize = find_font_size(string),
          fontweight = 300,
          family = 'sans-serif')
  return ax

# Function that defines the error text
def error_text():
  ax.text(x = 0.5, y = 0.5, s = 'Please input site_id into salesforce',
            horizontalalignment='center',
             verticalalignment='center',
           color = 'gray', fontsize = 20, family = 'sans-serif')
  return ax


# Final logic to figure out if an error message should be returned
if df.size == 0:
  periscope.output(error_text())
else:
  periscope.output(actual_text())
 
Version history
Last update:
‎02-09-2024 10:05 AM
Updated by:
Contributors
Community Toolbox

Recommended quick links to assist you in optimizing your community experience:

Developers Group:

Product Feedback Forum:

Need additional support?:

Submit a Support Request

The Legal Stuff

Have a question about the Sisense Community?

Email [email protected]

Share this page: