The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Can’t able to divide two data types.How to convert it into single data type

Can’t able to divide two data types.How to convert it into single data type

0
Votes
1
Answer

loan_data[‘mths_since_earliest_cr_line_date’] = round(pd.to_numeric(pd.to_datetime(‘2017-12-01’)-loan_data[‘earliest_cr_line_date’]) / np.timedelta64(‘1’, ‘M’))
 
Error:

func 'true_divide' cannot use operands with types dtype('int64') and dtype('<m8[ns]')
1 Answer

365 Team
0
Votes

Hey Nishant, 
 
I believe the “pd.to_numeric()” function is the problem here, since it transforms the datetype variables into integers before dividing by another datatype variable afterwards (np.timedelta64(‘1’, ‘M’)).
 
I suggest you add the division inside the to_numeric() and see if that solves it. 
 

loan_data['mths_since_earliest_cr_line_date'] = round(pd.to_numeric((pd.to_datetime('2017-12-01') - loan_data['earliest_cr_line_date']) / np.timedelta64('1', 'M')))

 
Best, 
365 Vik