Python 比较数据帧中以前和现在的哈希键值

Python 比较数据帧中以前和现在的哈希键值,python,dictionary,pandas,dataframe,data-analysis,Python,Dictionary,Pandas,Dataframe,Data Analysis,我想比较pandas数据帧中的a previous和Current dictionary键值。我有这样的想法: MyFrame= pd.DataFrame({"A":[6,4,7,10], "B":[8,10,90,100]}) for k,v in MyFrame.iteritems(): for k1,v1 in MyFrame[k].iteritems(): if MyFrame[k1+1]-MyFrame[k1]> 5: print("The thresho

我想比较pandas数据帧中的a previous和Current dictionary键值。我有这样的想法:

MyFrame= pd.DataFrame({"A":[6,4,7,10], "B":[8,10,90,100]})

for k,v in MyFrame.iteritems():

  for k1,v1 in MyFrame[k].iteritems():
        if MyFrame[k1+1]-MyFrame[k1]> 5: print("The threshold has been exceeded")

我想比较一下4和6,7和4,以及A栏中的一个。与“B”列相同。任何帮助都将不胜感激

不清楚您在尝试什么,但您可以通过调用
shift
来比较整个系列或df:

In [169]:
MyFrame['A'].shift()

Out[169]:
0   NaN
1     6
2     4
3     7
Name: A, dtype: float64

In [168]:
MyFrame.shift()

Out[168]:
    A   B
0 NaN NaN
1   6   8
2   4  10
3   7  90

比较7和6不是当前行和上一行的值。若要将一个序列与自身移动了一行的序列进行比较,请调用
shift
,以便将代码替换为
MyFrame['a']!=MyFrame['A'].shift()
或其他感谢您的内容。我有一个条件,就像以前的电流=5,打印(“阈值已被超出”)我想你的意思是,如果阈值大于5,无论如何,这将做同样的事情:
MyFrame-MyFrame>5
你是对的,它>5。但是如何根据键对当前值和以前的值进行索引呢。在第二个循环中,我使用MyFrame[k].iteritems():。那么,我将如何索引该循环中的键?MyFrame[k][k1]?为什么需要循环
MyFrame[MyFrame-MyFrame>5]
将显示哪些值符合该标准