Home > OS >  Shifting value from one row to another
Shifting value from one row to another

Time:07-29

So I have a dataset that has electricity load over 24 hours:

 Time_of_Day= loadData.groupby(loadData.index.hour).mean()
Time_of_Day

         Load
Time    
0   31.269373
1   26.810803
2   20.998901
3   18.513907
4   17.752296
5   19.093729
6   22.972921
7   29.144652
8   34.138466
9   37.169422
10  37.544159
11  37.499416
12  38.579195
13  38.251304
14  37.999605
15  38.832260
16  40.958003
17  46.695030
18  52.126723
19  55.921995
20  55.982203
21  53.431904
22  48.186216
23  39.799767

How would I please go about moving say half the load from 19:00 to 23:00? Any help or being pointed in the right direction will be appreciated.

CodePudding user response:

Something like this.

df = pd.DataFrame({'time': [0, 1, 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23], 
      'load': [31.269373,   26.810803,  20.998901,  18.513907,  17.752296,  19.093729,  22.972921,  29.144652,  34.138466,  37.169422,  37.544159,  37.499416,  38.579195,  38.251304,  37.999605,  38.83226,   40.958003,  46.69503,   52.126723,  55.921995,  55.982203,  53.431904,  48.186216,  39.799767]}
)

df.loc[df['time']==23, 'load']  = (df.loc[df['time']==17,'load'].values)/2
print(df )
time       load
0      0  31.269373
1      1  26.810803
2      2  20.998901
3      3  18.513907
4      4  17.752296
5      5  19.093729
6      6  22.972921
7      7  29.144652
8      8  34.138466
9      9  37.169422
10    10  37.544159
11    11  37.499416
12    12  38.579195
13    13  38.251304
14    14  37.999605
15    15  38.832260
16    16  40.958003
17    17  46.695030
18    18  52.126723
19    19  55.921995
20    20  55.982203
21    21  53.431904
22    22  48.186216
23    23  63.147282
  • Related