メソッドを実行するインスタンスはリストである必要がある
(失敗例)
slist = ['str1','str2','str3','str4','str5','str6'] adlist = ['details1','details2'] →slist[0].append(adlist)を実行すると AttributeError: 'str' object has no attribute 'append'が表示
(成功例)
[slist[0]].append(adlist)
pythonのfor文は処理が呼び出し関係で時間がかかるらしい
→なるべくforを使わずに書くことが時間短縮になる
for i in range(len(df12)):
if(i%200 ==0):
print(i)
for j in range(len(df12)):
if(i != j):
for k in range(len(df12.iloc[i,:])):
if(df12.iloc[i,k]==""):
break
for l in range(len(df12.iloc[j,:])):
if(df12.iloc[i,k] == df12.iloc[j,l]):
admatrix.iloc[i,j] +=1
16時間(200要素)*40 = 640時間(26.7日)超非効率!!
for i in range(len(df12)):
if(i%200 ==0):
print(i)
for j in range(len(df12)):
if(i != j):
#print(len((set(df12.iloc[i,1:])&set(df12.iloc[j,1:])-{""})))
admatrix.iloc[i,j]
=len((set(df12.iloc[i,1:])&set(df12.iloc[j,1:])-{""}))
O(n^2)、n=8100で約6.67時間(200要素(10分)*40)かかる