Unable to substract Yesterday's close price from Today's close price from a data frame using pandas

Dear Guru's.



I have downloaded BHAV copy for today and yesterday from NSE and using read_csv read the file



I am trying to calculate the price change and then the price % change for the asset. However I am unable to use the substract function. 



Below is the code.



The columns:



T_CLOSE is todays close price

Y_CLOSE is yesterdays close price

 

# percentage change in price 
analysis_df['pct_price_chg']= analysis_df(,['T_CLOSE'] - ['Y_CLOSE'])

I have tried this as well.

 

# percentage change in price 
analysis_df['pct_price_chg']= analysis_df['T_CLOSE'] - analysis_df['Y_CLOSE']

Could you please suggest how to proceed.



 

Hello,



There might be different reasons you are not able to us the subtract function, one of which could be that the length of the data is different in both csv files. 



Also, I noticed there is an extra comma in the code you have sent (before ['T_CLOSE']

# percentage change in price 
analysis_df['pct_price_chg']= analysis_df(,['T_CLOSE'] - ['Y_CLOSE'])

Without access to the files or the error, we can only speculate. Is it possible for you to send the file to quantra@quantinsti.com and we can help further.