1

So I've essentially got this setup. I have a dataframe consisting of this:

> df.head()
>        stock   timestamp   open   high    low  adj_close   volume
0       GERN  1532988000   3.34   3.59   3.59       3.59  4650479
1       GERN  1532901600   3.36   3.45   3.45       3.30  3571600
2       GERN  1532642400   3.44   3.50   3.50       3.34  2928697
3       GERN  1532556000   3.26   3.56   3.56       3.44  4209642
4       GERN  1532469600   3.37   3.42   3.42       3.22  3568900
5       GERN  1532383200   3.41   3.45   3.45       3.35  3323260

And essentially I want to shift the price of open back 1 day and 30 days and make new columns for this so I came up with this little piece of code, but for some reason the new_df is not being appended too, why is that?

import pandas as pd


df = pd.read_csv("financial_data_2000_2018_cleaned.csv", index_col=0)

# list of stucks that have all datapoints
stocks_list = ['GERN', 'CMCSA', 'AAPL', 'INTC', 'MSFT', 'QCOM', 'CSCO', 'NVDA',
               'SIRI', 'HBAN', 'SBUX', 'ATVI', 'ADSK', 'CA', 'AMAT', 'ROST',
               'HIBB', 'SYMC', 'EBAY', 'PZZA', 'GILD', 'MYL', 'ENDP', 'ADBE',
               'ESRX', 'MRVL', 'CELG', 'BBBY', 'FNSR', 'URBN', 'FAST', 'AMZN']

new_df = pd.DataFrame()

for stock in stocks_list:
    stock_df = df.loc[df['stock'] == stock]
    stock_df_cp = stock_df.copy()
    stock_df_cp['1_day_shift_open'] = stock_df_cp['open'].shift(1)
    stock_df_cp['30_day_shift_open'] = stock_df_cp['open'].shift(30)
    new_df.append(stock_df_cp)
PEREZje
  • 2,272
  • 3
  • 9
  • 23

0 Answers0