I have a function called plot_ih_il that receives two data frames in order to generate a plot. I also have a set of folders that each contain a .h5 file with the data I need to give to the function plot_ih_il… I’m trying to feed the function two datasets at a time but unsuccessfully.
I’ve been using pathlib to do so
JavaScript
x
6
1
path = Path("files")
2
3
for log in path.glob("log*"):
4
for file in log.glob("log*.h5"):
5
df = pd.DataFrame(file, key = "log")
6
but using this loop, I can only feed one data frame at a time, I need two of them.
The structure of the folders is something like,
JavaScript
1
5
1
files->log1-> log1.h5
2
log2-> log2.h5
3
log3-> log3.h5
4
log4-> log4.h5
5
I would like to feed the function plot_il_ih the following sequence,
JavaScript
1
3
1
plot_il_ih(dataframeof_log1.h5, dataframeof_log2.h5) then
2
plot_il_ih(dataframeof_log2.h5, dataframeof_log3.h5) and so on.
3
I have tried to use zip
JavaScript
1
8
1
def pairwise(iterable):
2
3
a = iter(iterable)
4
return zip(a, a)
5
6
for l1, l2 in pairwise(list(path.glob('log*'))):
7
plot_il_ih(l1, l2)
8
but it doesn’t move forward, just opens the 2 firsts.
What is wrong with my logic?
Advertisement
Answer
consider something like this. You might have to play around with the indexing
JavaScript
1
6
1
filelist = list(path.glob('log*'))
2
for i in range(1, len(filelist)):
3
print(filelist[i-1])
4
print(filelist[i])
5
print('n')
6