- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试读取 Excel 并将数据写入带有新列的新 Excel。
这是一个示例 Excel module
: 请忽略表格格式
+-------+------+------+
| Col1 | Col2 | Col3 |
+-------+------+------+
| Prod1 | "ABC | 100 |
XYZ"
| Prod2 | Test | 200 |
+-------+------+------+
df = pd.read_excel(module)
df["Status"] = ""
rowIndex = df.index[df['Col1'] == 'Prod1'].tolist()
df.loc[rowIndex, 'Status'] = 'Yes'
df
在一个新的excel中:
df.to_excel("output.xlsx", index = None, header=True)
+-------+----------+------+-------+
| Col1 | Col2 | Col3 | Status|
+-------+----------+------+-------+
| Prod1 | "ABCXYZ" | 100 | Yes |
| Prod2 | Test | 200 | |
+-------+----------+------+-------+
"ABCXYZ"
排成一行。我希望它像在旧的 excel 中一样位于多行中。在新的 Excel 中写入数据时,我可以对代码进行哪些更改以保留这种格式?
df
值为
"ABC\nXYZ"
但它仍然写在一行中。
最佳答案
我在下面找到了帮助我实现格式化的 python 库:
from StyleFrame import StyleFrame, Styler, utils
StyleFrame(df, styler_obj=Styler(horizontal_alignment=utils.horizontal_alignments.left, font = utils.fonts.calibri)).to_excel("output4.xlsx", index = None, header=True).save()
关于python - Pandas to_excel 不写换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59264311/
I am using xlsxwriter as the engine that I pass to pandas.ExcelWriter. I have a DataFrame and I c
我使用xlsxWriter作为引擎传递给pandas.ExcelWriter。我有一个DataFrame,并在其上调用to_exel(),传递我之前获得的编写器。然后,我尝试使用GET_WORKSHE
我正在使用 to_excel 将多个 DataFrame 写入多个 Excel 文档。这工作正常,除了数据框的索引以粗体附加在每个单元格周围并带有边框(见图)。 以下代码是我使用的代码的简化,但有同样
有没有办法使用 pandas to_excel 函数写入桌面,无论哪个用户正在运行脚本?我找到了 VBA 的答案,但没有找到 python 或 pandas 的答案。 最佳答案 pandas.Data
我就废话不多说了,大家还是直接看代码吧~ ? 1
我有一个具有12,000行和34列的数据框。 Pandas 大约需要15秒才能将此内容写入Excel。我读到的关于to_excel函数的讨论很少,而使其更快的一种方法是添加engine ='xlsxw
我正在尝试读取 Excel 并将数据写入带有新列的新 Excel。 这是一个示例 Excel module : 请忽略表格格式 +-------+------+------+ | Col1 | Co
我的 df 中有微秒分辨率,这非常重要,但无论我尝试什么,我都无法使用 .xls 或 .xlsx 显示微秒分辨率。关于如何在不显式转换为字符串的情况下让它们显示的任何想法? 最佳答案 使用 GitHu
我试图让 float_format 参数与 pandas 的 to_excel() 函数一起使用,但它似乎没有做任何事情。 代码: df = pd.DataFrame({ 'date'
运行 MixedLM 并希望将输出推送到 Excel 或 CSV,请参阅下面的模型代码和输出: model = smf.mixedlm('y_var ~ gas_prices', dfModel,
是否可以使用 pandas 的 excel writer 设置字体名称? 这是我的尝试: import pandas as pd from pandas.io.excel import ExcelWr
我有一个只有字符串的 Pandas 数据框,虽然有些是日期字符串,如“2019-01-01”,其他是整数或 bool 值,如字符串,如“1084”和“FALSE”。当我尝试将其写入 xlsx 文件中的
这个问题在这里已经有了答案: Pandas XLSWriter - return instead of write (1 个回答) 关闭 4 年前。 我最近不得不获取数据框并准备将其输出到 Exce
我写过这样的Excel表格 writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter') df.to_excel(writer, sheet_na
当我使用df.to_excel将数据保存在文件上时,pandas中有一个选项可以保留文件的格式吗? 我发现的唯一解决方法是: from openpyxl import load_workbook im
当我使用df.to_excel将数据保存在文件上时,pandas中有一个选项可以保留文件的格式吗? 我发现的唯一解决方法是: from openpyxl import load_workbook im
鉴于此数据 import pandas as pd dt1 = pd.Timestamp('2018-01-11 23:00:00') dt2 = pd.Timestamp('2018-01-12 0
每当我们使用 to_excel 函数将数据框保存到 pandas 中的 excel 文件 (.xlsx) 时,我们都会有一个选项来指定我们希望使用哪个引擎来完成该过程。我的问题是有哪些可用的引擎?例如
有没有办法在使用pandas的to_excel()函数后忽略重复的列名? 比如说,我有 old_wb.xlsx: >> df1 = pd.read_excel('wb1.xlsx')
我有一个多索引数据框,我必须将其另存为 excel 文件。当我使用 pandas 方法“to_excel”这样做时,我得到了一个包含合并单元格的漂亮表格。以下是此类表格的示例: 不幸的是,在 exce
我是一名优秀的程序员,十分优秀!