I have dataframe and i am using pandastable to show the data gui , I want to show different color in my B column , if B column has 'X' as a value then show green cell x else if 'Y' value then show red cell color.
I know we can do by table.setColorbyValue() but i am not getting the example to table.setColorbyValue() can you please tell me how to use table.setColorbyValue()
import tkinter as tk
import pandas as pd
from pandastable import Table
# --- functions ---
def on_select(val):
if val == 'all':
pt.model.df = df
else:
pt.model.df = df[ df['TIME'] == val ]
# refresh/redraw table in window
pt.redraw()
# --- main ---
df = pd.DataFrame({
'TIME': ['00:00','00:00','01:00','01:00','02:00','02:00'],
'A': ['a','b','c','d','e','f'],
'B': ['x','x','y','y','z','z'],
})
root = tk.Tk()
# create frame for pandas table
table_frame = tk.Frame(root)
table_frame.pack()
# add pandastable do frame
pt = Table(table_frame, dataframe=df) # it can't be `root`, it has to be `frame`
pt.show()
values = ['all'] + list(df['TIME'].unique())
selected = tk.StringVar()
options = tk.OptionMenu(root, selected, *values, command=on_select)
options.pack()
root.mainloop()