こんにちは私はCSVファイルを取得し、各顧客データを繰り返し処理しようとしています。説明するために、各顧客は12ヶ月のデータを持っています。私は彼らの年次データを分析し、このデータの相関を新しいリストに保存し、すべての顧客が分析されるまでこれをループしたいと思います。ここで例えばCSVで繰り返す解析済みデータを削除する
は、顧客データは(単純化の場合)のように見えるかもしれないものである:私は1つの顧客データのCSVでの相関関係を生成するために動作するようにこれを取得することができました
。しかし、私のデータシートには何千もの顧客がいます。私はネストされたforループを使用して、各顧客のすべての相関値をリスト/配列にしたいと考えています。リストには特定の顧客の相関の行があり、次の行は次の顧客になります。
import numpy
from numpy import genfromtxt
overalldata = genfromtxt('C:\Users\User V\Desktop\CUSTDATA.csv', delimiter=',')
emptylist = []
overalldatasubtract = overalldata[13::]
#This is where I try to use the four loop to go through all the customers. I don't know if len will give me all the rows or the number of columns.
for x in range(0,len(overalldata),11):
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)
#This is where I try to delete the rows I have already analyzed.
overalldata = overalldata[11**x::]
print result_correlation_combined
print overalldatasubtract
私のサブトラクション法が働いていたようだったが、私は私の大きなデータセットでそれをしようとしたとき、私は私の方法は完全に間違っている実現:
は、ここに私の現在のコードです。
これは別の方法ですか?私はそれが動作すると思うが、私は間違いを見つけることができない。
おかげで、これは、しかし、私はまだ任意の出力を取得していない午前、私がやろうとしたものであるように思われます。 結果の相関関係を保存する: result_correlation_combined = emptylist.append(result_correlation) ただし、空のリストを取得し続けるため、これは何も保存していないようです。 –