相关疑难解决方法(0)

根据值合并行(pandas to excel - xlsxwriter)

我正在尝试使用 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)

python excel pandas xlsxwriter

3
推荐指数
2
解决办法
6807
查看次数

标签 统计

excel ×1

pandas ×1

python ×1

xlsxwriter ×1