我正在創建一個程序來計算我的客戶數據之間的相關性。我想將相關值打印到CSV,以便我可以進一步分析數據。Numpy Savetxt覆蓋,找不到放置迴路的位置
我已經成功地讓我的程序循環遍歷所有客戶(每個數據12個月),同時計算他們的多個安排的個人關聯。如果我打印到對話框中,我可以看到這一點。
但是,當我嘗試使用Savetxt保存時,我只獲得了我計算的最終值。
我想我把我的循環放在錯誤的地方,它應該去哪裏?我試過檢查其他問題,但並沒有給它提供太多的信息。
編輯:我已經試圖對齊寫作與外循環和內循環建議,都產生了相同的結果。
for x_customer in range(0,len(overalldata),12):
for x in range(0,13,1):
cust_months = overalldata[0:x,1]
cust_balancenormal = overalldata[0:x,16]
cust_demo_one = overalldata[0:x,2]
cust_demo_two = overalldata[0:x,3]
num_acct_A = overalldata[0:x,4]
num_acct_B = overalldata[0:x,5]
#Correlation Calculations
demo_one_corr_balance = numpy.corrcoef(cust_balancenormal, cust_demo_one)[1,0]
demo_two_corr_balance = numpy.corrcoef(cust_balancenormal, cust_demo_two)[1,0]
demo_one_corr_acct_a = numpy.corrcoef(num_acct_A, cust_demo_one)[1,0]
demo_one_corr_acct_b = numpy.corrcoef(num_acct_B, cust_demo_one)[1,0]
demo_two_corr_acct_a = numpy.corrcoef(num_acct_A, cust_demo_two)[1,0]
demo_two_corr_acct_b = numpy.corrcoef(num_acct_B, cust_demo_two)[1,0]
result_correlation = [(demo_one_corr_balance),(demo_two_corr_balance),(demo_one_corr_acct_a),(demo_one_corr_acct_b),(demo_two_corr_acct_a),(demo_two_corr_acct_b)]
result_correlation_combined = emptylist.append([result_correlation])
cust_delete_list = [0,(x_customer),1]
overalldata = numpy.delete(overalldata, (cust_delete_list), axis=0)
numpy.savetxt('correlationoutput.csv', numpy.column_stack(result_correlation), delimiter=',')
print result_correlation
你的假設聽起來是對的。你應該unindent最後一個'savetxt'行 –
這是拋出一個「意外縮進錯誤」 –
沒有縮進應該這樣做(與外部'for'對齊) –