我正在尝试使用 xlsxwriter 将 Pandas 数据框输出到 excel 文件中。但是我正在尝试应用一些基于规则的格式;专门尝试合并具有相同值的单元格,但在想出如何编写循环时遇到了麻烦。(这里是 Python 新手!)
请参阅下面的输出与预期输出:
(正如您根据上图所见,当 Name 列下的单元格具有相同的值时,我正在尝试合并它们)。
这是我迄今为止所拥有的:
#This is the logic you use to merge cells in xlsxwriter (just an example)
worksheet.merge_range('A3:A4','value you want in merged cells', merge_format)
#Merge Car type Loop thought process...
#1.Loop through data frame where row n Name = row n -1 Name
#2.Get the length of the rows that have the same Name
#3.Based off the length run the merge_range function from xlsxwriter, worksheet.merge_range('range_found_from_loop','Name', merge_format)
for row_index in …Run Code Online (Sandbox Code Playgroud)