获得一些包含某些资产df
的返回的数据框。我想创建一个具有超额回报的新的即,即每列与1m_Tbill
之间的差异。
In[2]: df
Out[2]:
sp500 1m_Tbill MCD LUV AIG
Period
1997-01-31 0.061317 0.0045 0.002755 0.000000 0.118938
1997-02-28 0.005928 0.0039 -0.047802 0.068707 -0.001032
1997-03-31 -0.042614 0.0043 0.092486 -0.058511 -0.029132
1997-04-30 0.058406 0.0043 0.132275 0.242938 0.094782
1997-05-30 0.058577 0.0049 -0.059206 -0.063216 0.053502
1997-06-30 0.043453 0.0037 -0.038557 0.004854 0.104155
1997-07-31 0.078123 0.0043 0.112549 0.120773 0.069456
1997-08-29 -0.057446 0.0041 -0.118233 -0.034084 -0.113850
我尝试使用以下代码执行此操作
R0 = df['1m_Tbill']
Re = df[['MCD','LUV','AIG','sp500']]
Re['sp500'] -= R0
然而,这给我发出以下警告
SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
Re['sp500'] -= R0
如何正确地做到这一点?