【发布时间】:2020-11-06 19:02:30
【问题描述】:
我对 Python 很陌生。我有一个元组列表,我在其中创建了二元组。
This question 非常接近我的需求
my_list = [('we', 'consider'), ('what', 'to'), ('use', 'the'), ('words', 'of')]
现在我正在尝试将其转换为频率矩阵
想要的输出是
consider of the to use we what words
consider 0 0 0 0 0 0 0 0
of 0 0 0 0 0 0 0 0
the 0 0 0 0 0 0 0 0
to 0 0 0 0 0 0 0 0
use 0 0 1 0 0 0 0 0
we 1 0 0 0 0 0 0 0
what 0 0 0 1 0 0 0 0
words 0 1 0 0 0 0 0 0
如何做到这一点,使用numpy 或pandas?不幸的是,我只能看到 nltk 的内容。
【问题讨论】:
标签: python pandas numpy matrix text