如何解决迭代文件夹,每 2 个文件夹执行一个函数
我有一个名为 plot_ih_il 的函数,它接收两个数据帧以生成绘图。我还有一组文件夹,每个文件夹都包含一个 .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 提供以下序列,
plot_il_ih(dataframeof_log1.h5,dataframeof_log2.h5) then
plot_il_ih(dataframeof_log2.h5,dataframeof_log3.h5) and so on.
我尝试使用 zip
def pairwise(iterable):
a = iter(iterable)
return zip(a,a)
for l1,l2 in pairwise(list(path.glob('log*'))):
plot_il_ih(l1,l2)
但它没有前进,只是打开了两个第一。
我的逻辑有什么问题?
解决方法
考虑这样的事情。您可能需要处理索引
float *stack,*tmp1;
stack = malloc(4 * sizeof(*stack));
tmp1 = stack; // Now stack and tmp1 point to the same memory
stack[0] = 1.0;
stack[1] = 1.1;
stack[2] = 1.2;
stack[3] = 1.3;
// no memcpy here
for (int i = 0; i < 4; i++) {
printf("stack[%d]=%f,tmp1[%d]=%f\n",i,stack[i],tmp1[i]);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。