0
我有一個df pandas,列中只有'Price'和索引日期。我想找到一個名爲「APROX」新列內從Python/Pandas中查找近似值的一年內日期
aprox. = price of today - price of one year ago (or closest date from a year ago) -
price in one year (again take aprox if exact one year price don't exist)
for example
aprox. 2019-04-30 = 8 -4 -10 = -6 = aprox. 2019-04-30
- aprox. 2018-01-31 - aprox.2020-07-30
說實話我與有些strugling ...
ex. [in]: Price
2018-01-31 4
2019-04-30 8
2020-07-30 10
2020-10-31 9
2021-01-31 14
2021-04-30 150
2021-07-30 20
2022-10-31 14
[out]: Price aprox.
2018-01-31 4
2019-04-30 8 -6 ((8-4-10) = -6) since there is no 2018-04-30
2020-07-30 10 -12 (10-14-8)
2020-10-31 9 ...
2021-01-31 14 ...
2021-04-30 150
2021-07-30 20
2022-10-31 14
我strugling非常與...甚至更多與約。
非常感謝!
嗨,謝謝你的回覆@ aquil.abdullah!這不是我正在尋找的。例如,對於2019-04-30,「約」欄應回報2019-04-30(此處爲8)的價格,減去一年前的價格減去一年後的價格。如果在我的數據集之前或之後沒有確切的一年的價格,我只想從這一年中選擇最接近的價格/日期,所以這裏是2020-07-30和2018-01-31的價格。 微積分應該是8 - 4 - 10 = - 6 – user6457870