简体   繁体   中英

How to use datetime index from a Series to modify another series?

I have 2 Series with datetime index. I want to edit the values (float) of the first one at each corresponding daily minimum of the second one.

I tried

ser_1.loc[ser_2.groupby(ser_2.index.day_of_year).idxmin()] += 1

But I get this error:

raise KeyError(f"None of [{key}] are in the [{axis_name}]")

series 2 and 1,respectively, are shaped

2019-01-01 00:00:00    0.04980
2019-01-01 01:00:00    0.04426
2019-01-01 02:00:00    0.05100
2019-01-01 03:00:00    0.04627
2019-01-01 04:00:00    0.03978
                        ...   
2019-12-31 19:00:00    0.04773
2019-12-31 20:00:00    0.04600
2019-12-31 21:00:00    0.04220
2019-12-31 22:00:00    0.03974
2019-12-31 23:00:00    0.03888
Name: 0, Length: 8760, dtype: float64

2019-01-01 23:00:00    0.000
2019-01-02 00:00:00    0.000
2019-01-02 01:00:00    0.000
2019-01-02 02:00:00    0.000
2019-01-02 03:00:00    0.000
                       ...  
2019-12-13 06:00:00    1.534
2019-12-13 07:00:00    2.425
2019-12-13 08:00:00    1.622
2019-12-13 09:00:00    1.974
2019-12-13 10:00:00    1.729
Freq: H, Name: 1, Length: 8292, dtype: float64

Could it be a non correspondig index format or just bad use of a function?

Found my problem

The function I used is correct

But ser_1 is incomplete and some values can't correspond

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM