小编Sid*_*Sid的帖子

从 pandas 列中按另一列分组的列表中查找频繁元素

我的数据框如下所示

col1      col2
type1     ['A','C','B','D']
type1     ['C','A','F','E']
type1     ['F','E','G','H']
type2     ['A','E','F','G']
type2     ['A','E','J','K']
Run Code Online (Sandbox Code Playgroud)

我必须从 col2 的列表中找出给定用户输入中经常出现的元素。例如,如果用户输入是 A。那么我们必须找到与 A 一起出现的前 3 个元素。并且必须针对 col1 中的每个值进行计算。IE

type1 - most frequent element for A - A,C will be the output
type2 - most frequent element for A - A,E will be the output
Run Code Online (Sandbox Code Playgroud)

此处发布的数据是示例数据。

python counter python-3.x pandas pandas-groupby

5
推荐指数
1
解决办法
205
查看次数

如何在 k-means 聚类中使用 tfidf 值

我使用 sckit-learn 库将 K-means 聚类与 TF-IDF 结合使用。我知道 K-means 使用距离来创建集群,距离用(x 轴值,y 轴值)表示,但 tf-idf 是单个数值。我的问题是这个 tf-idf 值是如何通过 K-means 聚类转换为 (x,y) 值的。

nlp tf-idf k-means python-3.x tfidfvectorizer

2
推荐指数
1
解决办法
2645
查看次数

绘制python中计数器给出的最常见单词

最常用的单词列表输出如下:

[('电影', 904), ('电影', 561), ('one', 379), ('like', 292)]

我想要一个根据数字对每个单词使用 matplotlib 的图形

请帮我

python counter graph matplotlib python-3.x

0
推荐指数
1
解决办法
5594
查看次数

根据具有 x 个元素的列表对具有 n 个元素的元组进行排序

我有一个如下所示的元组

all_combi= [
    ('a', 33.333333333333336),
    ('a', 38.333333333333336),
    ('a', 43.333333333333336),
    ('a', 48.333333333333336),
    ('a', 53.333333333333336),
    ('a', 58.333333333333336),
    ('a', 63.333333333333336),
    ('a', 68.33333333333334),
    ('a', 73.33333333333334),
    ('a', 78.33333333333334),
    ('a', 83.33333333333334),
    ('a', 88.33333333333334),
    ('a', 93.33333333333334),
    ('a', 98.33333333333334),
    ('b', 33.333333333333336),
    ('b', 38.333333333333336),
    ('b', 43.333333333333336),
    ('b', 48.333333333333336),
    ('b', 53.333333333333336),
    ('b', 58.333333333333336),
    ('b', 63.333333333333336),
    ('b', 68.33333333333334),
    ('b', 73.33333333333334),
    ('b', 78.33333333333334),
    ('b', 83.33333333333334),
    ('b', 88.33333333333334),
    ('b', 93.33333333333334),
    ('b', 98.33333333333334),
    ('c', 33.333333333333336),
    ('c', 38.333333333333336),
    ('c', 43.333333333333336),
    ('c', 48.333333333333336),
    ('c', 53.333333333333336),
    ('c', 58.333333333333336),
    ('c', 63.333333333333336),
    ('c', 68.33333333333334),
    ('c', 73.33333333333334),
    ('c', 78.33333333333334),
    ('c', …
Run Code Online (Sandbox Code Playgroud)

python sorting tuples list python-3.x

0
推荐指数
1
解决办法
66
查看次数