gpt4 book ai didi

python - Pandas read_json 打开的文件太多错误

转载 作者:行者123 更新时间:2023-11-28 18:31:07 24 4
gpt4 key购买 nike

在执行以下操作时,我不断收到“打开的文件过多”错误:

# 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 保留指向打开文件的指针(应该只返回一个字符串列表)。

我哪里错了?

最佳答案

这似乎是系统问题,而不是 pandas 问题。

您可能需要增加系统中打开的文件数。

如何增加数量: https://easyengine.io/tutorials/linux/increase-open-files-limit/

以下问答: IOError: [Errno 24] Too many open files:讨论ulimit和打开文件的限制

此问答讨论了 Linux 中打开文件的数量: https://unix.stackexchange.com/questions/36841/why-is-number-of-open-files-limited-in-linux

关于python - Pandas read_json 打开的文件太多错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37255386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com