Warm tip: This article is reproduced from stackoverflow.com, please click
pandas

Calculate peak change from pandas dataframe

发布于 2020-03-29 21:02:23

I have following dataframe which will vary based on input. I am trying to figure out transition point which impact into data. any input

  Case 1.

     0         1         2         3       typ       min       max
1   0.000909  0.300938  0.292558  0.313002  0.000010  0.000007  0.000774
2   0.005968  0.300951  0.292570  0.312440  0.000043  0.000041 -0.001796
3   0.006764  0.300953  0.292572  0.311946  0.000007  0.000007 -0.001581
4   0.008185  0.300957  0.292575  0.310937  0.000013  0.000010 -0.003235
5   0.009208  0.300960  0.292578  0.310148  0.000010  0.000010 -0.002537
6   0.010402  0.300963  0.292580  0.309156  0.000010  0.000007 -0.003198
7   0.011368  0.300966  0.292583  0.308271  0.000010  0.000010 -0.002863
8    0.01279  0.300970  0.292586  0.306815  0.000013  0.000010 -0.004723
9   0.013813  0.300972  0.292589  0.305538  0.000007  0.000010 -0.004162
10  0.014779  0.300975  0.292591  0.304038  0.000010  0.000007 -0.004909
11  0.015575  0.300977  0.292593  0.302699  0.000007  0.000007 -0.004404
12  0.015859  0.300978  0.292593  0.302168  0.000003  0.000000 -0.001754
13  0.016314  0.300979  0.292595  0.301443  0.000003  0.000007 -0.002399
14  0.016996  0.300981  0.292596  0.300146  0.000007  0.000003 -0.004303
15  0.017508  0.300982  0.292597  0.299205  0.000003  0.000003 -0.003135
16  0.017678  0.300983  0.292598  0.298827  0.000003  0.000003 -0.001263
17  0.018076  0.300984  0.292599  0.298072  0.000003  0.000003 -0.002527
18   0.01836  0.300985  0.292599  0.297507  0.000003  0.000000 -0.001896
19  0.018985  0.300986  0.292601  0.296386  0.000003  0.000007 -0.003768
20  0.020179  0.300990  0.292604  0.294196  0.000013  0.000010 -0.007389
21  0.021202  0.300992  0.292606  0.292435  0.000007  0.000007 -0.005986
22  0.021714  0.300994  0.292607  0.291578  0.000007  0.000003 -0.002931
23  0.022112  0.300995  0.292608  0.290906  0.000003  0.000003 -0.002305
24   0.02251  0.300996  0.292609  0.290245  0.000003  0.000003 -0.002272
26   0.02359  0.300999  0.292612  0.288489  0.000007  0.000007 -0.003272
27  0.024386  0.301001  0.292614  0.287268  0.000007  0.000007 -0.004232
28  0.025807  0.301005  0.292617  0.285206  0.000013  0.000010 -0.007178
29  0.025977  0.301044  0.292618  0.284958  0.000130  0.000003 -0.000870
30  0.027512  0.301393  0.292621  0.282895  0.001159  0.000010 -0.007240
31   0.02791  0.301484  0.292622  0.282290  0.000302  0.000003 -0.002139

In above dataframe line no 29 has started transition

29  0.025977  0.301044  0.292618  0.284958  0.000130  0.000003 -0.000870

Case 2

      0         1         2         3       typ       min       max
4   0.001194  0.201683  0.194885  0.214935  0.000015  0.000010  0.001458
5    0.00523  0.201693  0.194893  0.214559  0.000050  0.000041 -0.001749
6   0.006594  0.201697  0.194895  0.213747  0.000020  0.000010 -0.003785
7   0.007503  0.201700  0.194897  0.213104  0.000015  0.000010 -0.003008
8   0.008185  0.201701  0.194898  0.212558  0.000005  0.000005 -0.002562
9   0.009379  0.201705  0.194900  0.211561  0.000020  0.000010 -0.004690
10  0.010175  0.201707  0.194901  0.210851  0.000010  0.000005 -0.003356
11  0.011596  0.201710  0.194904  0.209424  0.000015  0.000015 -0.006768
12  0.012676  0.201713  0.194906  0.208007  0.000015  0.000010 -0.006766
13  0.013699  0.201716  0.194907  0.206381  0.000015  0.000005 -0.007817
14  0.014722  0.201719  0.194909  0.204393  0.000015  0.000010 -0.009633
15  0.015291  0.201720  0.194910  0.203034  0.000005  0.000005 -0.006649
16  0.015575  0.201721  0.194911  0.202310  0.000005  0.000005 -0.003566
17   0.01603  0.201722  0.194911  0.201306  0.000005  0.000000 -0.004963
18  0.016485  0.201723  0.194912  0.200002  0.000005  0.000005 -0.006478
19  0.016996  0.201725  0.194913  0.198653  0.000010  0.000005 -0.006745
21  0.017394  0.201726  0.194914  0.197549  0.000005  0.000000 -0.002797
22  0.017792  0.201727  0.194915  0.196430  0.000005  0.000005 -0.005664
23  0.018588  0.201729  0.194916  0.194170  0.000010  0.000005 -0.011505
24  0.018929  0.201730  0.194917  0.193318  0.000005  0.000005 -0.004388
25  0.019497  0.201731  0.194918  0.191616  0.000005  0.000005 -0.008804
26   0.02052  0.201734  0.194919  0.188806  0.000015  0.000005 -0.014665
27  0.020805  0.201735  0.194920  0.187972  0.000005  0.000005 -0.004417
28  0.021203  0.201736  0.194921  0.186870  0.000005  0.000005 -0.005863
29   0.02143  0.201737  0.194921  0.186322  0.000005  0.000000 -0.002933
31  0.022624  0.201740  0.194923  0.183106  0.000010  0.000005 -0.011504
34  0.024102  0.201744  0.194926  0.179265  0.000010  0.000010 -0.011164
35  0.025295  0.201747  0.194928  0.176363  0.000015  0.000010 -0.016188
36  0.025693  0.201841  0.194928  0.175395  0.000466  0.000000 -0.005489
37  0.027228  0.202203  0.194931  0.171957  0.001793  0.000015 -0.019601

In above case, has big transition impact

36 0.025693 0.201841 0.194928 0.175395 0.000466 0.000000 -0.005489

Questioner
user765443
Viewed
31
Jim Eisenberg 2020-01-31 19:02

It seems like the transition is seen by big changes in typ - why not add a column showing rolling changes in typ?

df['typ_change'] = df.typ/df.typ.shift()

This shows how different typ is on row n compared to typ on row n-1.

For case 1 top typ_change values:

29    10.000000
30     8.915385
20     4.333333
2      4.300000
26     2.333333

for case 2:

36    31.066667
9      4.000000
37     3.847639
5      3.333333
26     3.000000