保存到Excel文件时,to_excel函数合并单元格

时间:2017-07-21 11:53:26

标签: python pandas

我有一个如下所示的Excel文件:

CompanyName    High Priority     QualityIssue
Customer1         Yes             User
Customer1         Yes             User
Customer2         No              User
Customer3         No              Equipment
Customer1         No              Neither
Customer3         No              User
Customer3         Yes             User
Customer3         Yes             Equipment
Customer4         No              User

我想计算每个CompanyName类型QualityIssue中每个实例的显示时间,并按外观下降的数量排序。

例如,使用此代码:

df.groupby(["CompanyName ", "QualityIssue"]).size()

我明白了:

Out:

CompanyName       QualityIssue    Count
Customer2         User            1
Customer1         Neither         1
Customer4         User            1
Customer1         User            2
Customer3         Equipment       2
Customer3         User            2

然后我用:

out.to_frame().sort_values(by='Count').to_excel('out.xlsx')

得到:

CompanyName       QualityIssue    Count
Customer2         User            1
Customer1         Neither         1
Customer4         User            1
Customer1         User            2
Customer3         Equipment       2
                  User            2

请注意,在最后两行中:

Customer3         Equipment       2
                  User            2

Customer3的行与下一行合并,因此Customer3是通过合并2行创建的1个单元格,而其他信息显示在不同的行上。这里的问题是如果我想将Excel文件保存到.csv我会得到2行,第一行是Customer3 Equipment 2,第二行是空单元格User 2,但它应该是{ {1}}而不是空单元格。

保存到Excel但是重复名称时不合并单元格的任何解决方案?如在python的输出中?

1 个答案:

答案 0 :(得分:3)

我认为let animation = CABasicAnimation(keyPath: "position") animation.timingFunction = CAMediaTimingFunction(controlPoints: 0.86, 0, 0.07, 1.0) animation.duration = 0.5 animation.fromValue = NSValue(cgPoint: CGPoint(x: viewObject.center.x, y: viewObject.center.y)) animation.toValue = NSValue(cgPoint: CGPoint(x: viewObject.center.x + 64, y: viewObject.center.y)) viewObject.layer.add(animation, forKey: "position") 来自columns的{​​{1}}需要reset_index

MultiIndex