簡體   English   中英

python Dataframe中的數學運算(加法和冪)

[英]Math operations (addition and power) in python Dataframe

我目前有這個數據框

Date
1987-01-26   -0.629487
1988-01-25    0.552159
1989-01-23    0.247890
1990-01-22    0.294639
1991-01-21    0.400885
1992-01-20    0.099296
1993-01-18    0.256380

第二列包含3年回報。 我想替換現有列,3年回報率(R),與equivallent1年收益率(R),使得: 等式

我相信需要numpy.power

df['R'] = np.power(1 + df['Col'], 1/3) - 1

numpy.cbrt

df['R'] = np.cbrt(1 + df['Col']) - 1

print (df)
         Date       Col         R
0  1987-01-26 -0.629487 -0.281763
1  1988-01-25  0.552159  0.157832
2  1989-01-23  0.247890  0.076611
3  1990-01-22  0.294639  0.089891
4  1991-01-21  0.400885  0.118925
5  1992-01-20  0.099296  0.032060
6  1993-01-18  0.256380  0.079047

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM