メソッドを実行するインスタンスはリストである必要がある
(失敗例)
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)
問題(n×1)型の配列
In: t =[[{'a':1}],[{'a':2}],[{'a':3}],[{'a':4}],[{'a':5}]]
Out: [[{'a': 1}], [{'a': 2}], [{'a': 3}], [{'a': 4}], [{'a': 5}]]
データフレーム時,aで一まとめにしてくれない
appendで新しい1次元配列に入れ直していく(内包表記で表現)
In: c = [t[i][0] for i in range(len(t))]
Out: [{'a': 1}, {'a': 2}, {'a': 3}, {'a': 4}, {'a': 5}]
データフレーム時,Columnsをaとしてまとめてくれる
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日:Core i7-9700K)超非効率!!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)かかる