- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将从一张图片开始,因为它清楚地解释了使用 pandas native 导出和 xlwings 导出多重索引的问题
本质上,我希望使用 Xlwings
完成“Pandas
原生”结果[正确导出到 Excel 的多重索引],因为我还有很多其他功能XlWings
可以做到,而其他人则不能(即使使用 ExcelWriter
之类的也不行,因为我必须清除工作表,并且我在同一张工作表中插入了一个非 python 的东西,这会初始化时也会被清除)
使用的代码:
import pandas as pd
import numpy as np
import xlwings as xw
import os
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
s = pd.DataFrame(np.random.randn(8, 8), index=index).transpose()
print(s)
# EXPORT
filename = 'format_excel_export.xlsx'
s.to_excel(filename)
outpath = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
os.path.sep = r'/'
wb = xw.Workbook(outpath)
xw.Range('Sheet1', 'A13').value = s
最佳答案
您可以实现一个自定义转换器,以 Pandas 的方式对其进行格式化,请参阅 here .
但是,从 v0.7.2 开始,xlwings 本身尚不支持粗体字体、合并单元格和单元格边框。您可以通过回退到 pywin32(在 Windows 上)来解决此问题,请参阅 here .
本质上,您的自定义转换器需要重写 write_value
方法,请参阅 here .
在某个时候将其构建到库中确实有意义,因此我提出了一个问题,请参阅 here .
关于excel - xlwings 与 pandas 本地导出与多索引数据帧 : how to reconcile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38305346/
我想在不使用演示协调器的情况下在 Eclipse 中进行着色。因此,首先,我需要弄清楚如何将 TextPresentation 对象与我的编辑器或文档相关联,但我很难找到如何将它们链接起来。通常,IP
每当我使用 RKE 设置 Rancher Kubernetes 集群时,该集群就会完美设置。但是,我收到以下警告消息: WARN[0011] [reconcile] host [host.exampl
我有一个 Eclipse 自定义编辑器,我实现了“键入时报告错误”,但我的错误波浪线(使用 JFace 注释)不时显示或在删除后仍然存在。 我将 MonoReconciler 与我的 IReconci
我将从一张图片开始,因为它清楚地解释了使用 pandas native 导出和 xlwings 导出多重索引的问题 本质上,我希望使用 Xlwings 完成“Pandas 原生”结果[正确导出到 Ex
我下载了最新的 p4 工具,但它缺少 reconcile 命令: $ p4 -V Perforce - The Fast Software Configuration Management Syste
我们曾经在使用 xaml 构建定义时从我们的 Windows 机器的托盘中获得完成构建的通知,它还有一个选项来协调工作区。相同的功能不适用于 vNext 版本。 BuildNotification A
在适用于 32-bin Windows 的 Perforce Visual Client 2009.1 版本中,“协调离线工作”选项会执行奇怪的操作。在应该显示“本地文件不在仓库中”的中间框中,我什么
我的 Flex 项目 (AS3) 中出现了一个非常奇怪的调用堆栈。 Main Thread (Suspended: VerifyError: Error #1068: Array a
我正在将所有模块迁移到 Poetry,但遇到了问题。 在使用 python setup.py 测试 之前,我能够使用正确的覆盖信息运行我的测试。 现在我要转向诗歌,所以我最好的选择是 poetry r
如果我在 P4V 中执行“Reconcile Offline Work”,一段时间后协调将完成,最终会弹出一个窗口,显示已修改、添加或删除的文件。有时,根据目录中的大量文件,我知道协调将需要几分钟或更
我的实验性双节点 Kubernetes 1.13.2 不幸进入了第二个节点为 NotReady 的模式。 .我试过systemctl restart kubelet在两个节点上,但到目前为止这没有帮助
我正在设置一个项目,以在配置的服务器上使用TFS,并且我选择使用封闭式 checkin 策略。完成此操作后, checkin 代码时,我将按照以下步骤顺序进行操作: 执行 checkin 。 选择“在
我有一些平均 yaml 文件定义了一些平均角色资源,所有 yaml 都应该反射(reflect)我的资源所需的状态。 为了让新的平均角色进入集群,我通常运行 kubectl apply -f my-n
经过 git pull origin master我收到以下消息: warning: Pulling without specifying how to reconcile divergent bra
我已经无数次使用以下 CLI 命令创建了 AKS。直到今天我都没有问题。 az aks create --resource-group rg --name ama --generate-ssh-ke
假设我有两个数据集 base 和 payment。 base 是: [ id, timestamp, value] 付款是: [ payment_id, timestamp, value, gate
因此,我在 XCode 4.5.2 中有一个 iOS 项目,当我尝试在模拟器中运行它时,它不断抛出“无法附加到进程 ID 0”错误,如该线程中所述: Failed to Attach to Proce
我是一名优秀的程序员,十分优秀!