mardi 29 juin 2021

Check descending order in a column using FOR loop and IF ELSE in python

   time           1           2  ...          10          11          12
0    114         NaN         NaN  ...         NaN         NaN         NaN
1    115         NaN         NaN  ...         NaN         NaN         NaN
2    116         NaN         NaN  ...         NaN         NaN         NaN
3    117         NaN         NaN  ...         NaN         NaN         NaN
4    118         NaN         NaN  ...         NaN         NaN         NaN
5    119  441.352927         NaN  ...         NaN         NaN         NaN
6    120  441.832005         NaN  ...         NaN         NaN         NaN
7    121  429.159441  414.695159  ...         NaN         NaN         NaN
8    122  426.640083  409.350283  ...         NaN         NaN         NaN
9    123  405.895463  391.782682  ...         NaN         NaN  595.583477
10   124  348.333084  330.328054  ...         NaN         NaN  558.149675
11   125  269.575895  244.929717  ...  498.792684  174.485133  501.917091
12   126  206.326517  183.591386  ...  483.946063  159.790946  388.633450
13   127  164.460509  146.675092  ...  468.012384  143.278498  289.948133
14   128  136.459238  124.173664  ...  445.790269  126.418644  216.911347
15   129  118.142130  109.840042  ...  429.640427  114.967589  158.156775
16   130  106.305034  102.602261  ...  456.978328  105.465703  125.695873
17   131   95.334029   95.655744  ...  436.670517   98.330257  103.816534
18   132   86.695439   89.980695  ...  436.020305   90.027712   90.845685

I want to check,

for col in df.columns [1:]: #Check from column name 1 until 12 (skip the NaN)

if first 5 values are descending =TRUE, startpoint = the largest value from these 5 else, take next set of 5 values and do the same.

Create a separate dataframe for all the startpoint values until the end value for every column and also include the time column.

Aucun commentaire:

Enregistrer un commentaire