2

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.

1 Answer 1

1

Could the culprit be the following lines?

if data[8] == 1:
    next_month_data = data[1]

Shouldn't it be next_month_data[row_index] = data[1]?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.