【发布时间】:2021-02-18 12:56:31
【问题描述】:
我正在使用以下方法将数据框加载到熊猫中:
import pandas as pd
df_factor_histories=pd.read_excel("./eco_factor/eco_factor_test_data_builder.xlsx",
engine='openpyxl', sheet_name=0)
需要engine=openpyxl 才能启用read_excel 以支持更新的Excel 文件格式(特别是在我的情况下是.xlsx 而不是jusy .xls)。
数据框加载正常但文件保持打开状态:
import psutil
p = psutil.Process()
print(p.open_files())
OUTPUT
[popenfile(path='C:\\Users\\xx\\.ipython\\profile_default\\history.sqlite', fd=-1),
popenfile(path='C:\\Windows\\System32\\en-US\\KernelBase.dll.mui', fd=-1),
popenfile(path='C:\\Windows\\System32\\en-US\\kernel32.dll.mui', fd=-1),
popenfile(path='D:\\xxxxx\\data modelling\\eco_factor\\eco_factor_test_data_builder.xlsx', fd=-1)]
Github Post 表明该错误已修复 - 但不适用于我(运行 Anaconda/Jupyter)。 我正在运行的相关版本:
numpy 1.19.2
openpyxl 3.0.5
pandas 1.1.3
Python 3.7.4
我将不胜感激有关如何关闭文件/解决此问题的最佳方法的一些建议,谢谢
【问题讨论】:
标签: python pandas openpyxl file-handling