0

I'm kind of new to python, today I was trying to do some operations in a financial DataFrame (first column of YYYY-MM-DD and second one of values). When I tried to apply a simple pct_change() operation, it gave me this error:

TypeError: ufunc true_divide cannot use operands with types 
dtype('<M8[ns]') and dtype('<M8[ns]')

What is this error exactly caused by? And how can I work around it? Because I couldn't really find many explanations online. Thanks a lot in advance!

iraciv94
  • 782
  • 2
  • 11
  • 26

1 Answers1

2

dtype('<M8[ns]') is one of the numpy datetime64 dtypes. So it looks like you are trying do your precentage change calculation on the date column which unsuprisingly doesn't work.

The solution would be to select the value column. (I can't be more specific since you are not providing the necessary details.)

Paul Panzer
  • 51,835
  • 3
  • 54
  • 99
  • I am getting the same error when am trying to apply np.busday_count() I want to know the business days between 2 days and run it on a dataframe column at the same time.. any thoughts pls? – spiff Oct 10 '18 at 07:04