列表索引超出范围(python jupyter)
我不知道如何解决这个问题。因为我复制了这段代码并根据我的项目进行了调整 编辑:OP在评论中提供的完整回溯列表索引超出范围(python jupyter),python,Python,我不知道如何解决这个问题。因为我复制了这段代码并根据我的项目进行了调整 编辑:OP在评论中提供的完整回溯 import pandas as pd films = { 'title': titles, 'rank': ranks, 'synopsis': synopses, 'cluster': clusters, 'genre': genres } #frame = pd.DataFrame(films[frame] for frame in films.keys()) frame = pd.
import pandas as pd
films = { 'title': titles, 'rank': ranks, 'synopsis': synopses, 'cluster': clusters, 'genre': genres }
#frame = pd.DataFrame(films[frame] for frame in films.keys())
frame = pd.DataFrame(films,columns = ['rank', 'title', 'cluster', 'genre'])
dups_shape = frame.pivot_table(index=['cluster'], aggfunc='size')
print (dups_shape)
items = { 'title': titles, 'Synopses': synopses}
frame = pd.DataFrame(items, index = [clusters] , columns = [ 'title','cluster'])
print("Top terms per cluster:")
# sort cluster centers by proximity to centroid
order_centroids = km.cluster_centers_.argsort()[:, ::-1]
for i in range(num_clusters):
print("Cluster %d words:" % i, end='')
for ind in order_centroids[i, :6]: # replace 6 with n words per cluster
print(' %s' % vocab_frame.loc[terms[ind].split(' ')].values.tolist()[0][0], end=',')
print()
每个集群的顶级术语:
群集0字:
---------------------------------------------------------------------------
索引器回溯(最后一次调用)
13
14对于按质心[i,:6]顺序排列的ind:#将6替换为每个簇n个字
--->15打印(“%s”%vocab_frame.loc[terms[ind].split(“”)].values.tolist()[0][0],end=',”
16
17索引器:列表索引超出范围
您能发布完整的回溯吗?我是说,整个错误信息?它可能会让我们对真正的问题有更多的了解。请同时添加错误,这样就很容易理解了。最有价值的是要查看哪一行抛出了错误。每个簇的顶级术语:簇0单词:-------------------------------------------------------------索引器跟踪(最后一次调用)在13 14中按质心[i,:6]的顺序为ind:#将6替换为每个簇n个字-->15个打印(“%s”%vocab_frame.loc[terms[ind].split(“”)].values.tolist()[0][0],end=,'))16 17 Indexer错误:列出索引超出范围这是关于tolist方法的错误消息:这些都是标量类型,是Python标量(对于str、int、float)还是pandas标量(对于Timestamp/Timedelta/Interval/Period)
您不是指索引[0]而不是[0][0]?你能发布完整的回溯吗?我的意思是,整个错误消息?它可能会让我们对真正的问题有更多的了解。请也添加错误,这样就很容易理解了。最有价值的是要查看哪一行抛出了错误。每个簇的顶级术语:簇0字:---------------------------------------------------------------------------索引器对ind的回溯(最近一次调用last)在13 14中,顺序为_质心[i,:6]:#将6替换为每个簇n个字-->15个打印(“%s”%vocab_frame.loc[terms[ind].split(“”)].values.tolist()[0][0],end=','))16 17 Indexer错误:列出索引超出范围这是关于tolist方法的错误消息:这些都是标量类型,是Python标量(对于str、int、float)或pandas标量(对于Timestamp/Timedelta/Interval/Period)
您不是指索引[0]而不是[0][0]?
Top terms per cluster:
Cluster 0 words:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last) <ipython-input-40-2088a7881446> in <module>
13
14 for ind in order_centroids[i, :6]: # replace 6 with n words per cluster
--->15 print(' %s' % vocab_frame.loc[terms[ind].split(' ')].values.tolist()[0][0], end=',')
16
17 IndexError: list index out of range