最终目标是,由于股票比例为20:1,我试图修改原始股票价格数据。
从raw_data
中,我使用以下代码提取了相关的ticker
('IPL')和date
(
raw_data[(raw_data['ticker'] =='IPL') & (raw_data['date']<'2008-10-01')]
结果数据框如下:
ticker date open high low close volume return
687 IPL 2008-01-02 117.00 118.48 116.81 117.16 150971.0 NaN
2146 IPL 2008-01-03 117.16 123.82 116.80 120.96 240929.0 0.032434
3617 IPL 2008-01-04 123.06 127.24 120.20 125.60 329834.0 0.038360
5156 IPL 2008-01-07 125.60 126.21 121.61 121.63 266578.0 -0.031608
6731 IPL 2008-01-08 119.70 121.93 118.75 119.58 362860.0 -0.016854
... ... ... ... ... ... ... ... ...
259572 IPL 2008-09-10 126.00 130.50 125.10 129.00 1046421.0 -0.030075
260940 IPL 2008-09-11 133.50 134.55 131.82 132.50 599706.0 0.027132
262251 IPL 2008-09-12 136.00 142.00 134.03 139.01 475591.0 0.049132
263608 IPL 2008-09-15 139.00 143.00 135.50 139.93 390052.0 0.006618
264980 IPL 2008-09-16 136.00 137.40 131.11 132.00 489557.0 -0.056671
我试图遍历for循环和.loc[]
,但我完全陷入困境。
我也尝试过以下&
和and
:
for i, row in raw_data.iterrows():
close_val = ['close']
if raw_data[(raw_data['ticker'] =='IPL') and (raw_data['date']<'2008-10-01')]:
close_val = ['close'] * 0.05
df.at[i,'close'] = close_val
但出现以下错误:
"ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()."
基本上,我需要将2008-09-17之前的所有价格open, high, low, close
乘以0.05,然后将volume
除以0.05。