{Guided Project: Clean and Analyze Employee Exit Surveys: Step 6} Get error: cannot use operands with types dtype('<M8[ns]')

Screen Link:


My Code:

dete_resignations['institute_service'] = dete_resignations['cease_date'] - dete_resignations['dete_start_date']

What I expected to happen:

I expect the code will work but it does not.

What actually happened:

UFuncTypeError: ufunc 'subtract' cannot use operands with types dtype('<M8[ns]') and dtype('float64')

As my understanding from above error, the issue because of different datatype (<M8[ns]) and float) that we can not subtract. However my code show both columns are int64 type, why does it show <M8[ns] type? How should I correct it.

Below are results when I print column for cease date and start date of DETE Surveys:

Name: cease_date, dtype: int64
Name: dete_start_date, dtype: int64

I also try to do this project on my local computer but it shows the same error.

Thanks so much in advance

This is a strange one, for sure! What has me confused is that the error says the dtypes are <M8[ns] and float64 but when you inspect the data it says it’s neither one of these: int64.

Can you please share your entire notebook so that others can see all the code involved? It seems like the data is being converted to a different dtype somewhere between creating the variables and where you actually do the subtraction.

Note: M8[ns] is related to datetime objects. Are you converting to datetime anywhere?

This is my work:
Emloyee_exit_surveys.py (110 Bytes)

I also convert datatype to datetime for the column "dete_resignations[“cease_date”], please have a look and advise me what is wrong with my code.

Many thanks in advance.