The end goal is that I am trying to modify raw stock price data as a result of a 20:1 stock split.
From raw_data
I extracted the relevant ticker
('IPL') and date
(< '2008-10-01') using the code below:
raw_data[(raw_data['ticker'] =='IPL') & (raw_data['date']<'2008-10-01')]
The result dataframe is below:
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
I have tried to iterate through for loops and .loc[]
but I am completely stuck.
I have also tried the below with &
and 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
But I get the following error:
"ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()."
Essentially, I need to multiply all prices open, high, low, close
prior to 2008-09-17 by 0.05 and divide volume
by 0.05.