我在我最喜欢的节目的剧集中对词进行了频率分析.我正在制作plot.barh(s1e1_y,s1e1_x),但它按字而不是值排序.输出>>> s1e1_y
是
['know', 'go', 'now', 'here', 'gonna', 'can', 'them', 'think', 'come', 'time', 'got', 'elliot', 'talk', 'out', 'night', 'been', 'then', 'need', 'world', "what's"]
Run Code Online (Sandbox Code Playgroud)
和 >>>s1e1_x
[42, 30, 26, 25, 24, 22, 20, 19, 19, 18, 18, 18, 17, 17, 15, 15, 14, 14, 13, 13]
实际绘制图表时,即使绘图列表未排序,图表的y轴刻度也会按字母顺序排序...
s1e1_wordlist = []
s1e1_count = []
for word, count in s1e01:
if((word[:-1] in excluded_words) == False):
s1e1_wordlist.append(word[:-1])
s1e1_count.append(int(count))
s1e1_sorted = sorted(list(sorted(zip(s1e1_count, s1e1_wordlist))),
reverse=True)
s1e1_20 = []
for i in range(0,20):
s1e1_20.append(s1e1_sorted[i])
s1e1_x = …Run Code Online (Sandbox Code Playgroud)