Toggle dark mode


Hi,

📢 Taipy v2.1 is about to be launched! 🚀 ETA:

Day(s)

:

Hour(s)

:

Minute(s)

:

Second(s)

M
December 18, 2022

pandas query

Welcome to Taipy Forums Taipy GUI pandas query

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #237388
    jpypjpyp
    Participant

    hi ,

    For a dashboard , I currently use pandas csv more easy to import dataframe.
    i don”t do much with number but got lot of string .

    the idea is to create a forms for people gathering evaluate (separate pages)
    on the dashboard we have the entities that we evaluate , the date of the evaluation , and the 5 criterias of evaluation

    the dashboard is only showing the result for one day .
    i want to do to filter 1. on the entities , second on the date.
    and let the dashboard update. could you give me or point me to some examples?

    I also later want to do so with sqlite3 files and sparql query any examples would be great !

    thanks in advane

    #237389
    jpypjpyp
    Participant

    indeed that example source code could really help

    |https://www.taipy.io/project/bar-cutting/|

    thanks in advance
    JP

    • This reply was modified 1 month, 2 weeks ago by jpypjpyp.
    • This reply was modified 1 month, 2 weeks ago by jpypjpyp.
    #237392
    Florian JactaFlorian Jacta
    Keymaster

    Hi,

    Here is a simple example of code to do some filtering on dates and string. If it is not enough, I can provide you with more complex example or I can give you access to the code of ‘Bar cutting”.

    
    from taipy.gui import Gui 
    import pandas as pd
    import datetime as dt
    import numpy as np
    
    # this function will filter the dataframe
    # we can have multiple functions to filter it depending on the
    # visual elements that have been changed to be more efficient
    def filter_data(data, input_str, start_date, end_date):
        index = (data['Date'] >  np.datetime64(start_date)) &\
                (data['Date'] <  np.datetime64(end_date)) &\
                (data["Value"].apply(lambda x: input_str in x))
        
        filtered_data = data[index]
        return filtered_data
    
    # processing of a DataFrame (two columns: Date, Value)
    original_data = pd.read_csv("graph_examples/airline_passengers.csv")
    original_data['Date'] = pd.to_datetime(original_data['Date']) 
    original_data['Value'] = original_data['Value'].astype(str)
    
    # Initialization of variables of the GUI
    input_for_filter = ""
    
    start_date = dt.datetime(1950,1,1)
    end_date = dt.datetime(1960,1,1)
    
    filtered_data = filter_data(original_data,
                                input_for_filter,
                                start_date,
                                end_date)
    
    # simple Markdown
    md = """
    <|{input_for_filter}|input|on_change=on_changer_filter|>
    
    <|{start_date}|date|on_change=on_changer_filter|> <|{end_date}|date|on_change=on_changer_filter|>
    
    <|{filtered_data}|table|>
    """
    
    # function called by the GUI to filter the dataframe when a change is being done
    # on visual elements
    def on_changer_filter(state):
        state.filtered_data = filter_data(original_data,
                                          state.input_for_filter,
                                          state.start_date,
                                          state.end_date)
        
    # GUI running
    Gui(md).run()
        
    

    I hope this will help you to create your own filtering. Don’t hesitate to come back to us.

    Best regards,
    Florian

    #237439
    jpypjpyp
    Participant

    Hi Florian,

    many thanks i will give it a try today 🙂

    Best regards
    Jean-Pol

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.