I'm getting the error TypeError: ("'numpy.float64' object does not support item assignment", 'occurred at index 4') when I attempt to assign values to elements in my numpy array sequentially. The value I'm attempting to assign to the element is a float so I have no idea what's going on.
My function is as follows:
def get_next_month_data(data):
next_month_data = np.zeros(data.shape, dtype=float)
data = data.values
row_index = 0
#SellerAccountID
next_month_data[row_index] = data[0]
row_index += 1
#CurrentBalance
if data[8] == 1:
next_month_data = data[1]
else:
next_month_data[row_index] = data[1] - (data[8] - data[1] * data[2])
row_index += 1
#calculated_rate
next_month_data[row_index] = data[2]
row_index += 1
#contractual_payment_propensity
next_month_data[row_index] = data[3]
row_index += 1
#arrears increase propensity
next_month_data[row_index] = data[4]
row_index += 1
#arrears decrease propensity
next_month_data[row_index] = data[5]
row_index += 1
#Number
next_month_data[row_index] = data[6]
row_index += 1
#pay_amnt
next_month_data[row_index] = 0
row_index += 1
#default flag
if data[9] < 6 and data[8] != 1:
next_month_data[row_index] = 0
else:
next_month_data[row_index] = 1
row_index += 1
#months in arrears
if data[7] == 0:
next_month_data[row_index] = data[9] + 1
elif data[7] == data[10]:
next_month_data[row_index] = data[9]
else:
next_month_data[row_index] = data[9] - 1
row_index += 1
#repayment value
next_month_data[row_index] = data[10]
row_index += 1
return next_month_data
The argument data is a pandas series. The error is always thrown at the line
next_month_data[row_index] = data[2]
All elements in my series are float values.
Please help this is so frustrating.