Python 自动查找非nan值及其对应的索引点

Python 自动查找非nan值及其对应的索引点,python,arrays,indexing,Python,Arrays,Indexing,根据与合法值(不是NaN)相对应的索引号自动查找不同点的值,因为根据我在初始数据上放置的函数,整个数据中将有许多NaN 我有一个数据框(名为“future”),在其中我选择了整个过程中相对最小/最大值的特定点(743个初始行),并能够将这些最小/最大值的索引点放置到数组中,并将它们添加到“graph”数据框(“closemin”、“closemax”、“rsimin”、“rsimax”)数组的值由“图形”数据框中各自列中这些最小/最大值的索引点组成 我试图找到相对接近的最小/最大值之间的斜率,然

根据与合法值(不是NaN)相对应的索引号自动查找不同点的值,因为根据我在初始数据上放置的函数,整个数据中将有许多NaN

我有一个数据框(名为“future”),在其中我选择了整个过程中相对最小/最大值的特定点(743个初始行),并能够将这些最小/最大值的索引点放置到数组中,并将它们添加到“graph”数据框(“closemin”、“closemax”、“rsimin”、“rsimax”)数组的值由“图形”数据框中各自列中这些最小/最大值的索引点组成

我试图找到相对接近的最小/最大值之间的斜率,然后将其与RSIE14在相同索引点的斜率进行比较。我可以很容易地找到索引点,但没有一种方法来自动化这个过程——我需要其他数据集,因为这些相对最小/最大点之间的NaN值会经常变化。 例如,在下图中,索引号351和340处有相对的“closemin”。我想自动获取这些索引点,然后同时为RSIE14数据获取相同的索引点(351和340),这样我就可以自动找到两者的斜率。

当您在这些行中循环时,您需要引用一个适用于两个数据帧的通用索引。在这里的示例中,我有两个数据帧,数据不同,但引用的索引相同。假设一个数据帧引用close数据,另一个引用closemin数据

这就是它的工作原理:

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]
----

因此,当我在行中循环并找到最小/最大点时,它们非常稀疏(很多NaN),并且对于我应用此循环的每个数据集都会发生变化。无论如何,是否需要隔离与此forloop给定的索引点相对应的最小/最大值,然后将简单的数学应用于。例如,当我在“futures DF:Value of”列24 123.15 127 163.45 179 176.98中运行此:索引时,我希望根据列的值计算差值。希望这是有意义的。你能用一个数据集和你想提取的数据的例子来编辑你的问题吗?我添加了一个新的图片和一个精确的解释。谢谢你的时间和努力!