Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone help me with the error in my python code?

I used np.subtract () where I got the following error.

Cannot convert input [(0, slice(None, None, None))] of type to Timestamp

stock_open=panel_data['Open']
stock_close=panel_data['Close']
row,col=stock_close.shape
movements = np.zeros([row, col])
for i in range(0, row):
    movements[i,:] = np.subtract(stock_close[i,:], stock_open[i,:])

The below line in my code:

movements[i,:] = np.subtract(stock_close[i,:], stock_open[i,:]) 

gives me the following error.

TypeError: Cannot convert input [(0, slice(None, None, None))] of type to Timestamp

like image 893
uranus1212 Avatar asked Mar 13 '26 14:03

uranus1212


1 Answers

use the below line

np.subtract(stock_close.values[i,:], stock_open.values[i,:])

or if you're looking for an even better way to do it :

stock_close.values[i,:] - stock_open.values[i,:]
like image 94
Lior Cohen Avatar answered Mar 15 '26 06:03

Lior Cohen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!