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
Example with setColorByValue()
but I think this function will not be so useful as you expect. Frankly, I don't understand why this function exists.
You have to set which columns to colorized and later run setColorbyValue()
but columns may need integer or float values. Or at least it will not work with strings.
pt.multiplecollist = [0, 2] # column's number
pt.setColorbyValue() # set colors using `pt.values_to_colors()`
Other problem: it open Dialog window and ask for some color.
Based on source code: setColorbyValue
import tkinter as tk
import pandas as pd
from pandastable import Table
df = pd.DataFrame({
'A': [1,2,3,4,5,6],
'B': [1,2,3,4,5,6],
'C': [1,2,3,4,5,6],
})
root = tk.Tk()
table_frame = tk.Frame(root)
table_frame.pack()
pt = Table(table_frame, dataframe=df) # it can't be `root`, it has to be `frame`
pt.show()
pt.multiplecollist = [0,2] # column's number
pt.setColorbyValue() # set colors using `pt.values_to_colors()`
root.mainloop()
BTW: more useful can be setColorByMask()
mask_1 = pt.model.df['A'] < 5
pt.setColorByMask('A', mask_1, 'red')
mask_2 = pt.model.df['A'] >= 5
pt.setColorByMask('A', mask_2, 'green')
import tkinter as tk
import pandas as pd
from pandastable import Table
df = pd.DataFrame({
'A': [1,2,3,4,5,6],
'B': [1,2,3,4,5,6],
'C': [1,2,3,4,5,6],
})
root = tk.Tk()
table_frame = tk.Frame(root)
table_frame.pack()
pt = Table(table_frame, dataframe=df) # it can't be `root`, it has to be `frame`
pt.show()
mask_1 = pt.model.df['A'] < 5
pt.setColorByMask('A', mask_1, 'red')
mask_2 = pt.model.df['A'] >= 5
pt.setColorByMask('A', mask_2, 'green')
root.mainloop()