在执行以下操作时,我一直收到“打开的文件太多”的错误:
# read file names
file_names = []
for file_name in os.listdir(path):
if '.json' not in file_name: continue
file_names.append(file_name)
# process file names...
# iter files
for file_name in file_names:
# load file into DF
file_path = path + '/' + file_name
df = pandas.read_json(file_path)
# process the data, etc...
# not real var names, just for illustration purposes...
json_arr_1 = ...
json_arr_2 = ...
# save DF1 to new file
df_1 = pandas.DataFrame(data=json_arr_1)
file_name2 = os.getcwd() + '/db/' + folder_name + '/' + file_name
df_1.to_json(file_name2, orient='records')
# save DF2 to new file
df_2 = pandas.DataFrame(data=json_arr_2)
file_name3 = os.getcwd() + '/db/other/' + folder_name + '/' + file_name
df_2.to_json(file_name3, orient='records')DF文档没有提到必须处理打开或关闭的文件,而且我认为listdir没有保存指向打开文件的指针(应该只返回字符串列表)。
我哪里出问题了?
发布于 2016-05-16 14:09:43
这似乎是一个系统问题,而不是熊猫问题。
您可能需要增加系统中打开的文件数。
如何增加数量:https://easyengine.io/tutorials/linux/increase-open-files-limit/
以下问题&A:IOError: [Errno 24] Too many open files:讨论了U极限和打开文件的限制
关于Linux中打开的文件数量的问答:https://unix.stackexchange.com/questions/36841/why-is-number-of-open-files-limited-in-linux
https://stackoverflow.com/questions/37255386
复制相似问题