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!

1
  • Can you show us an example of your dataframe and the code where this error occurred? Jun 13, 2018 at 7:45

1 Answer 1

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.)

1
  • 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, 2018 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.