私は単語のペアのリストを持っており、NetworkXが読むためのデータとしてそれらを準備しようとしています。スクリプトの一部がペアを反復してID番号にマッピングします(下記のコードを参照)。このコードは、私が過去に取得する必要のあるエラーIndex out of range
を投げます。ここで間違いは何ですか? len(row)
ここ常に1
に、あなたが使用することはできませんのでリストの索引が範囲外になっています
coocs = [['parttim;work'], ['parttim;work'],['parttim;visit'], ['parttim;site'], ['parttim;uncl'], ['parttim;home'], ['parttim;onlin']]
unique_coocs = list(set([row[0] for row in coocs])) # remove redundance
ids = list(enumerate(unique_coocs)) # creates a list of tuples with unique ids and their names for each word in the network
keys = {name: i for i, name in enumerate(unique_coocs)} # creates a dictionary(hash map) that maps each id to the words
links = [] # creates a blank list
for row in coocs: # maps all of the names in the list to their id number
try:
links.append({keys[row[0]]: keys[row[1]]})
except:
links.append({row[0]: row[1]})
何行が上のエラーです正常に動作しますか? –
これは 'links.append({row [0]:row [1]})' – textnet
です。エラーメッセージ全体を表示するのに役立ちます。 – Joel