Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

"min() arg error is empty sequence" error while trying to draw a count / barplot

$
0
0

currently learning to develop dashboard application with Shiny for Python, i'm facing issues while trying to plot a graph with filtered data.

i'm using an initial dataset, i want to filter using "patient name" or "date" i collect from data range selector or select box. to perform the data selection, i tried to setup a reactive fonction that make the row selection using pandas library.

when i want to display the graph (count plot for example), i receive the following message : min() arg is an empty sequence. i don't meet this error if i directly plot the graph with non filtered data.

so i guess there is something wrong during the filtering step :

from shiny.express import input, render, uifrom shiny import reactiveimport plotly.express as pximport pandas as pdimport numpy as npimport seaborn as snsfrom shinywidgets import reactive_read, render_widget  df_patient = pd.read_excel(r"C:\Users\rdesb\OneDrive\Bureau\MyAPP\dashboard\db_patient.xlsx",                            index_col="Indice")df_ABS = pd.read_excel(r"C:\Users\rdesb\OneDrive\Bureau\MyAPP\dashboard\Bdd_ABS.xlsx")liste_patient = pd.unique(df_ABS["Patient"])liste_patient = tuple(liste_patient)#df_patient["Date de naissance"] = pd.to_datetime(df_patient["Date de naissance"], format='%d-%m-%Y')#INTERFACE GRAPHIQUEui.page_opts(title="DashBoard Plume", fillable=True)with ui.nav_panel("Informations Patients"):    ui.h2("Informations Patients")    @render.data_frame      def patients_df():        return render.DataGrid(df_patient)  with ui.nav_panel("Statistiques"):    with ui.layout_columns():          with ui.card(full_screen=False, height=100):              ui.card_header("Selection de date")            ui.input_date_range("daterange", "Date range", start="2020-01-01")         with ui.card(full_screen=False, height=100):              ui.card_header("Selection patient")            ui.input_select(  "patient_select",  "Choisissez un patient:",                  liste_patient,  )      @reactive.Calc                    def df_ABS_sorted():        return df_ABS.loc[df_ABS["Patient"]== {input.patient_select()}]    with ui.layout_columns():        with ui.card(full_screen=False, height=700):              @render.plot(alt="Affichage données triées par patient et date")              def plot():                  ax = sns.countplot(data=df_ABS_sorted(), x="Patient")                  ax.set_title("Absences")                ax.set_xlabel("Nom")                ax.set_ylabel("Counts")                return ax              @render.text            def value():                return f"{input.patient_select()}"

enter image description here

i also tried not using reactive calculation and directly type the "filtered" conditions, that lead to the same error.

i guess there is something wrong typing directly :df_ABS.loc[df_ABS["Patient"]== {input.patient_select()}], maybe something conflcit with the type.

thank you for your help and have a good day.


Viewing all articles
Browse latest Browse all 23131

Trending Articles