首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >是否有一种方法可以根据Pandastable中列中的列值对行进行着色

是否有一种方法可以根据Pandastable中列中的列值对行进行着色
EN

Stack Overflow用户
提问于 2022-08-30 04:47:04
回答 2查看 62关注 0票数 0
代码语言:javascript
运行
复制
enter c

我要做的是根据列类型中的值更改行颜色。W=黄,E=红和I=蓝。我是刚接触传染病的人。任何想法

代码在这里

我想修改的表

代码语言:javascript
运行
复制
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)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-09-02 18:10:35

代码语言:javascript
运行
复制
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()
票数 0
EN

Stack Overflow用户

发布于 2022-09-01 22:18:38

furas给出了这样的答案:here,您需要如下所示:

代码语言:javascript
运行
复制
import tkinter as tk
import pandas as pd
from pandastable import Table

df = pd.DataFrame({
    'A': [1,2,3,'hi',5,'hi'],
    'B': [1,2,3,4,5,6],
    'C': [1,2,'ok',4,'ok',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'] == 'hi'
pt.setColorByMask('A', mask_1, 'red')
mask_2 = pt.model.df['B'] >= 5
pt.setColorByMask('B', mask_2, 'blue')
mask_3 = pt.model.df['C'] == 'ok'
pt.setColorByMask('c', mask_2, 'green')

root.mainloop()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73537265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档