简体   繁体   English

Pygsheets:如何根据条件突出显示特定列中的单元格

[英]Pygsheets: How to highlight cells in a specific column based on a condition

I have a pandas data frame with three columns, and I want to highlight the cells in a specific column that meet a certain condition using pygsheets.我有一个包含三列的 Pandas 数据框,我想使用 pygsheets 突出显示特定列中满足特定条件的单元格。 How can I do that?我怎样才能做到这一点?

A                 B          C 
some_text         65      some_text


def color_my_cell(var):
    for i in wks.range('B3:B30'):
        if var < 70:
           wks.cell( NOT SURE what to do here).color = (1.0,0,1.0,1.0)

df['B'] = df['B'].apply(color_my_cell)

So, for any cells in B < 70, highlight cells blue.因此,对于 B < 70 中的任何单元格,将单元格突出显示为蓝色。

you cant apply formats in df directly.您不能直接在 df 中应用格式。 you can do this by coloring cells by acessing each cell and setting color.您可以通过访问每个单元格并设置颜色来为单元格着色。 but i think in your case whats more appropriate is conditional formatting.但我认为在你的情况下更合适的是条件格式。 something like shown below.如下所示。 below code might not be exatly what you require refer to here and here下面的代码可能不是您所需要的,请参阅此处此处

request = {"AddConditionalFormatRuleRequest": {
"ranges":[GridRange(worksheet=wks, start='B3', end='B30').to_json()],
"booleanRule": {
"condition":{"type::'NUMBER_GREATER', 'values': 70},
"format":{"backgroundColor":{"color": {"green": 0.8,},}}}},
"index":0}

ssheet.custom_request(request, "*")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Pandas 样式突出显示具有不同条件的每列的特定单元格 - Python Pandas style highlight specific cells for each column with different condition 如何根据 Pandas 中的行和列值突出显示单元格? - How can I highlight cells based on row and column values in Pandas? 如何根据条件替换 Panda 数据框列中的单元格 - How do I replace cells in a Panda dataframe column based on a condition 在散点图中突出显示特定点(基于条件) - Highlight specific points (based on a condition) in a scatter plot 使用 Pygsheets 查找单元格并更新同一列中的单元格 - Finding cell using Pygsheets and update cells in the same column 如何使用pygsheets在特定文件夹中打开电子表格 - How to open a spreadsheet in a specific folder using pygsheets 如何通过每列的不同条件突出显示 dataframe 中的某些单元格? 是否也可以突出显示系列中的某些数字? - How to highlight some cells in a dataframe through different condition for each column? Is also possible highlighting some number in a Series? 将函数应用于单行以根据条件突出显示单元格 - Apply function to single row in order to highlight cells based on condition 如何在一列中基于特定单元格的值插入重复行 - How to insert deplicated rows based on values of specific cells in one column 如何为列中的单元格着色? 熊猫,pygsheets - How to colorize the cell in column? Pandas, pygsheets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM