Python 在文件夹上迭代,每2个文件夹执行一个功能

Python 在文件夹上迭代,每2个文件夹执行一个功能,python,python-3.x,pandas,pathlib,Python,Python 3.x,Pandas,Pathlib,我有一个名为plot_ih_il的函数,它接收两个数据帧以生成一个plot。我还有一组文件夹,每个文件夹都包含一个.h5文件,其中包含我需要提供给函数plot_ih_il的数据。。。我试图一次向函数提供两个数据集,但没有成功 我一直在使用pathlib来实现这一点 path = Path("files") for log in path.glob("log*"): for file in log.glob("log*.h5"

我有一个名为plot_ih_il的函数,它接收两个数据帧以生成一个plot。我还有一组文件夹,每个文件夹都包含一个.h5文件,其中包含我需要提供给函数plot_ih_il的数据。。。我试图一次向函数提供两个数据集,但没有成功

我一直在使用pathlib来实现这一点

path = Path("files")

 for log in path.glob("log*"):
     for file in log.glob("log*.h5"):
       df = pd.DataFrame(file, key = "log")
但是使用这个循环,我一次只能提供一个数据帧,我需要两个数据帧

文件夹的结构类似于

files->log1-> log1.h5
       log2-> log2.h5
       log3-> log3.h5
       log4-> log4.h5
我想按以下顺序输入函数图

plot_il_ih(dataframeof_log1.h5, dataframeof_log2.h5) then
plot_il_ih(dataframeof_log2.h5, dataframeof_log3.h5) and so on.
我试过用拉链

def pairwise(iterable):
    
    a = iter(iterable)
    return zip(a, a)

for l1, l2 in pairwise(list(path.glob('log*'))):
    plot_il_ih(l1, l2)
但它没有前进,只是打开了两个第一


我的逻辑出了什么问题?

考虑一下这样的问题。你可能不得不玩弄索引

filelist = list(path.glob('log*'))
for i in range(1, len(filelist)):
    print(filelist[i-1])
    print(filelist[i])
    print('\n')

这正是我需要的,非常感谢!