Can't able to divide two data types.How to convert it into single data type
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 answers ( 0 marked as helpful)
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