- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试 concat
床单 xlsx
文件,我发现以下错误:
Traceback (most recent call last):
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\xml\etree\ElementTree.py", line 832, in _get_writer
yield file.write
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\xml\etree\ElementTree.py", line 772, in write
serialize(write, self._root, qnames, namespaces,
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\xml\etree\ElementTree.py", line 937, in _serialize_xml
_serialize_xml(write, e, qnames, None,
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\xml\etree\ElementTree.py", line 937, in _serialize_xml
_serialize_xml(write, e, qnames, None,
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\xml\etree\ElementTree.py", line 937, in _serialize_xml
_serialize_xml(write, e, qnames, None,
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\xml\etree\ElementTree.py", line 931, in _serialize_xml
write(" %s=\"%s\"" % (qnames[k], v))
MemoryError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/Python Projects/MyAuditPy/pd_read.py", line 265, in <module>
join2.to_excel("shared_BM_NL_Q2_DNS.xlsx")
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\generic.py", line 2175, in to_excel
formatter.write(
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\io\formats\excel.py", line 738, in write
writer.save()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\io\excel\_openpyxl.py", line 43, in save
return self.book.save(self.path)
File "D:\Python Projects\MyAuditPy\venv\lib\site-packages\openpyxl\workbook\workbook.py", line 392, in save
save_workbook(self, filename)
File "D:\Python Projects\MyAuditPy\venv\lib\site-packages\openpyxl\writer\excel.py", line 293, in save_workbook
writer.save()
File "D:\Python Projects\MyAuditPy\venv\lib\site-packages\openpyxl\writer\excel.py", line 275, in save
self.write_data()
File "D:\Python Projects\MyAuditPy\venv\lib\site-packages\openpyxl\writer\excel.py", line 75, in write_data
self._write_worksheets()
File "D:\Python Projects\MyAuditPy\venv\lib\site-packages\openpyxl\writer\excel.py", line 215, in _write_worksheets
self.write_worksheet(ws)
File "D:\Python Projects\MyAuditPy\venv\lib\site-packages\openpyxl\writer\excel.py", line 200, in write_worksheet
writer.write()
File "D:\Python Projects\MyAuditPy\venv\lib\site-packages\openpyxl\worksheet\_writer.py", line 360, in write
self.close()
File "D:\Python Projects\MyAuditPy\venv\lib\site-packages\openpyxl\worksheet\_writer.py", line 368, in close
self.xf.close()
File "D:\Python Projects\MyAuditPy\venv\lib\site-packages\openpyxl\worksheet\_writer.py", line 299, in get_stream
pass
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py", line 120, in __exit__
next(self.gen)
File "D:\Python Projects\MyAuditPy\venv\lib\site-packages\et_xmlfile\xmlfile.py", line 50, in element
self._write_element(el)
File "D:\Python Projects\MyAuditPy\venv\lib\site-packages\et_xmlfile\xmlfile.py", line 77, in _write_element
xml = tostring(element)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\xml\etree\ElementTree.py", line 1133, in tostring
ElementTree(element).write(stream, encoding,
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\xml\etree\ElementTree.py", line 772, in write
serialize(write, self._root, qnames, namespaces,
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\xml\etree\ElementTree.py", line 832, in _get_writer
yield file.write
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py", line 525, in __exit__
raise exc_details[1]
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py", line 510, in __exit__
if cb(*exc_details):
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\lib\contextlib.py", line 382, in _exit_wrapper
callback(*args, **kwds)
ValueError: I/O operation on closed file.
这是我的相关代码:
import os
import pandas as pd
shared_BM_NL_Q2_DNS = 'Shared_BM_NL_Q2_DNS.xlsx'
shared_BM_NL_Q2_DNS_df1 = pd.read_excel(os.path.join(os.path.dirname(__file__), shared_BM_NL_Q2_DNS), sheet_name='client31_KPN')
shared_BM_NL_Q2_DNS_df2 = pd.read_excel(os.path.join(os.path.dirname(__file__), shared_BM_NL_Q2_DNS), sheet_name='client32_T-Mobile')
shared_BM_NL_Q2_DNS_df3 = pd.read_excel(os.path.join(os.path.dirname(__file__), shared_BM_NL_Q2_DNS), sheet_name='client33_Vodafone')
#shared_BM_NL_Q2_DNS
shared_BM_NL_Q2_DNS_df1.columns = shared_BM_NL_Q2_DNS_df1.columns.str.replace(' ', '_')
shared_BM_NL_Q2_DNS_df1.columns = shared_BM_NL_Q2_DNS_df1.columns.str.replace('\n', '')
shared_BM_NL_Q2_DNS_df1.columns = shared_BM_NL_Q2_DNS_df1.columns.str.replace(r"[^a-zA-Z\d\_]+", "")
shared_BM_NL_Q2_DNS_df1.columns = map(str.lower, shared_BM_NL_Q2_DNS_df1.columns)
shared_BM_NL_Q2_DNS_df2.columns = shared_BM_NL_Q2_DNS_df2.columns.str.replace(' ', '_')
shared_BM_NL_Q2_DNS_df2.columns = shared_BM_NL_Q2_DNS_df2.columns.str.replace('\n', '')
shared_BM_NL_Q2_DNS_df2.columns = shared_BM_NL_Q2_DNS_df2.columns.str.replace(r"[^a-zA-Z\d\_]+", "")
shared_BM_NL_Q2_DNS_df2.columns = map(str.lower, shared_BM_NL_Q2_DNS_df2.columns)
shared_BM_NL_Q2_DNS_df3.columns = shared_BM_NL_Q2_DNS_df3.columns.str.replace(' ', '_')
shared_BM_NL_Q2_DNS_df3.columns = shared_BM_NL_Q2_DNS_df3.columns.str.replace('\n', '')
shared_BM_NL_Q2_DNS_df3.columns = shared_BM_NL_Q2_DNS_df3.columns.str.replace(r"[^a-zA-Z\d\_]+", "")
shared_BM_NL_Q2_DNS_df3.columns = map(str.lower, shared_BM_NL_Q2_DNS_df3.columns)
dataframes2 = [shared_BM_NL_Q2_DNS_df1, shared_BM_NL_Q2_DNS_df2, shared_BM_NL_Q2_DNS_df3]
join2 = pd.concat(dataframes2).reset_index(drop=True)
join2.to_excel("shared_BM_NL_Q2_DNS.xlsx")
作为这一行中的错误:
join2.to_excel("shared_BM_NL_Q2_DNS.xlsx")
我还需要有人建议我如何为这样的代码执行一种好方法
最佳答案
最后我找到了解决方案,这是因为 xlsx
中的行数限制因为我解决了而不是转换 to_excel
正在使用 to_csv
如以下代码:
join2.to_csv("shared_BM_NL_Q2_DNS.csv")
关于python - 值错误 : I/O operation on closed file to_excel pandas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62988232/
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
我是一名优秀的程序员,十分优秀!