analysis.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:seinfeld-analysis 作者: christopherjenness 项目源码 文件源码
def plot_word_frequency(df, words, category):
    plt.figure()
    allwords = df['lines'].str.cat(sep=' ')
    allwords = allwords.split()
    allwords = [word.lower() for word in allwords]
    allwords = np.array(allwords)
    indices = []
    for word in words:
        new_indices = np.where(allwords == word)
        for index in new_indices[0]:
            indices.append(index)

    sns.distplot(indices, rug=True, hist=False)
    plt.xlim(0, len(allwords))
    plt.ylabel("{category} word frequency".format(category=category))
    plt.xlabel("Time (words)")
    plt.title("{category} words over time".format(category=category),
              loc='left')
    plt.savefig("../plots/{category}_frequency".format(category=category))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号