根据数据框的大小动态选择行
Selecting rows dynamically based on the size of the Dataframe
我正在尝试根据数据框的大小将条件格式应用于一系列单元格:
percent_fmt = workbook.add_format({'num_format': '0.00%'})
range_1 = ## This should have the range of rows starting cell 'C23' to the number of rows in the dataframe
我计划使用 df.shape[0]
获取 Dataframe 的大小,并尝试将此计数添加到 range_1
中的值。
所以如果 df.shape[0]
= 30 那么 range_1 = "C23:C53"
。 <- 因为格式化应该从 C23 开始,然后格式化接下来的 30 行。 30的计数是根据Dataframe的大小得到的。
worksheet.conditional_format(range_1, {'type': 'no_blanks', 'format': percent_fmt})
row_count = 30
range_1= f'C23:C{23+row_count}'
range_1
'C23:C53'
这是你要的吗?
我正在尝试根据数据框的大小将条件格式应用于一系列单元格:
percent_fmt = workbook.add_format({'num_format': '0.00%'})
range_1 = ## This should have the range of rows starting cell 'C23' to the number of rows in the dataframe
我计划使用 df.shape[0]
获取 Dataframe 的大小,并尝试将此计数添加到 range_1
中的值。
所以如果 df.shape[0]
= 30 那么 range_1 = "C23:C53"
。 <- 因为格式化应该从 C23 开始,然后格式化接下来的 30 行。 30的计数是根据Dataframe的大小得到的。
worksheet.conditional_format(range_1, {'type': 'no_blanks', 'format': percent_fmt})
row_count = 30
range_1= f'C23:C{23+row_count}'
range_1
'C23:C53'
这是你要的吗?