pandastable

Is there a way to color a row based on a column value in a column in Pandastable


enter c

What I want to do is to Change the row colors based on the values in the column TYPE. W =Yellow, E= Red and I= Blue. I am new to pandastable. Any Ideas

Code here

Table I want to modify

1

def ElogsOpen ():
    #function to strip logs and create a csv file
    elogstrip()
    # window off root parameters
    win = Toplevel(root)
    win.title('Elogs')
    win.geometry ( '1920x1080') 
    win.state('zoomed')
    win.resizable=False
    #File path where CSV was stored when generated
    filepath= folderbtn+'\elogs.csv'
    #Code to display Pandastable from CSV
    class TestApp(tk.Frame):
        def __init__(self, parent, filepath):
            super().__init__(parent)
            self.table = Table(self, showtoolbar=True, showstatusbar=True)
            self.table.importCSV(filepath)
            self.table.autoResizeColumns()
            self.table.show()
    app = TestApp(win, filepath)
    app.pack(fill=tk.BOTH, expand=1)

Solution

  • def ElogsOpen ():
    #function to strip logs and create a csv file
    elogstrip()
    # window off root parameters
    win = Toplevel(root)
    win.title('Elogs')
    win.state('zoomed')
    win.resizable=False
    df=elogdffinal
    #restes index
    df.reset_index(drop=True, inplace=True)
    #makes the index a column
    df = df.reset_index(level=0)
    #names index
    df.index.name = 'Index'
    #sets frame to win
    table_frame = tk.Frame(win)
    #Packs and makes the fram the wholwe screen
    table_frame.pack(fill=tk.BOTH, expand=1)
    #Puts index that has An E in the Column Type to a list
    row1=df.index[df['Type'] == "E "].tolist()
    #Puts index that has An I in the Column Type to a list
    row2=df.index[df['Type'] == "I "].tolist()
    #Puts index that has An W in the Column Type to a list
    row3=df.index[df['Type'] == "W "].tolist()
    #Makes the table
    pt = Table(table_frame, dataframe=df) # it can't be `root`, it has to be `frame`
    #Sets the rows by the list row1 to red
    pt.setRowColors(rows=row1, clr='#EEA2AD', cols='all')
    #Sets the rows by the list row1 to Blue
    pt.setRowColors(rows=row2, clr='#B0E2FF', cols='all')
    #Sets the rows by the list row1 to Yellow
    pt.setRowColors(rows=row3, clr='#FFF68F', cols='all')
    #Displays Table
    pt.show()