Когда вы проходите по этим строкам, вам необходимо обратиться к общему индексу, который применяется к обоим Датафреймам. В моем примере здесь у меня есть два кадра данных с разными данными, но ссылаются на один и тот же индекс. Допустим, один кадр данных относится к данным закрытия, а другой - к данным закрытия.
Вот как это может работать:
import pandas as pd
import random
my_randoms = [random.sample(range(100), 10), random.sample(range(100), 10)]
my_other_randoms = [random.sample(range(100), 10), random.sample(range(100), 10)]
first_dataframe = pd.DataFrame(my_randoms).T
second_dataframe = pd.DataFrame(my_other_randoms).T
print(first_dataframe)
print("----")
print(second_dataframe)
print("----")
for index, row in first_dataframe.iterrows():
print(f"Index of current row: {index} \n"
f"Values of current row: {row.values}\n"
f"Values on same row other DF: {second_dataframe.iloc[index].values}\n"
f"----")
С выходом:
0 1
0 90 61
1 99 88
2 15 56
3 17 37
4 95 93
5 23 43
6 68 14
7 7 9
8 97 2
9 53 91
----
0 1
0 6 88
1 21 51
2 2 50
3 38 40
4 11 67
5 57 80
6 9 41
7 88 47
8 41 72
9 42 52
----
Index of current row: 0
Values of current row: [90 61]
Values on same row other DF: [ 6 88]
----
Index of current row: 1
Values of current row: [99 88]
Values on same row other DF: [21 51]
----
Index of current row: 2
Values of current row: [15 56]
Values on same row other DF: [ 2 50]
----
Index of current row: 3
Values of current row: [17 37]
Values on same row other DF: [38 40]
----
Index of current row: 4
Values of current row: [95 93]
Values on same row other DF: [11 67]
----
Index of current row: 5
Values of current row: [23 43]
Values on same row other DF: [57 80]
----
Index of current row: 6
Values of current row: [68 14]
Values on same row other DF: [ 9 41]
----
Index of current row: 7
Values of current row: [7 9]
Values on same row other DF: [88 47]
----
Index of current row: 8
Values of current row: [97 2]
Values on same row other DF: [41 72]
----
Index of current row: 9
Values of current row: [53 91]
Values on same row other DF: [42 52]
----