0

Cant seem to find any information on adding to existing data frame with a calculated column.

Have converted my list of data to a data Frame then calculated the EMA by:

df = pd.DataFrame(stored_data,columns=['pair','timestamp','opening','high','low','closing','weighted','volume','count'])

df['ema100'] = pd.Series.ewm(df['closing'], span=100).mean()

if I print df.tail() I get the expected results:

         pair   timestamp  opening  ...      volume count        ema100
715  XXBTZUSD  1624106340  36079.9  ...  1.40772436    13  36020.935390
716  XXBTZUSD  1624106400  36077.7  ...  0.27966751     9  36022.033700
717  XXBTZUSD  1624106460  36076.3  ...  0.06391599     4  36023.108281
718  XXBTZUSD  1624106520  36076.3  ...  0.69499065    18  36024.161583
719  XXBTZUSD  1624106580  36076.3  ...  0.00495975     1  36025.194027

[5 rows x 10 columns]

But how do I add a new row to the dataframe and have it calculate the ema100 value on append?

Thanks

hulleyrob
  • 25
  • 6
  • 1
    Automatic update of calculated columns is not a feature in Pandas, you can try workarounds as given here: https://stackoverflow.com/questions/19988124/automatically-updating-columns-in-pandas – lytseeker Jun 19 '21 at 14:21
  • 1
    Ok that explains why I cant seem to do it thank you just thought I was missing something. – hulleyrob Jun 19 '21 at 14:57

0 Answers0