简体   繁体   English

有没有办法在另一列的列中找到每个值的出现次数?

[英]Is there a way to find the number of occurrences of each value in a column in another column?

I have two dataframes called dataset1 and dataset 2 (shown below).我有两个名为 dataset1 和 dataset 2 的数据框(如下所示)。 The "pattern" and "SAX" columns contain string values. “模式”和“SAX”列包含字符串值。

dataset1=
       pattern   tstamps
0    glngsyu     1610460
1    zicobgm     1610466
2    eerptow        .
3    cqbsynt        .
4    zvmqben        .
..       ...
475  rfikekw
476  bnbzvqx
477  rsuhgax
478  ckhloio
479  lbzujtw

480 rows × 1 columns

dataset2 =
    SAX     timestamp
0   hssrlcu 16015
1   ktyuymp 16016
2   xncqmfr 16017
3   aanlmna 16018
4   urvahvo 16019
... ... ...
263455  jeivqzo 279470
263456  bzasxgw 279471
263457  jspqnqv 279472
263458  sxwfchj 279473
263459  gxqnhfr 279474

263460 rows × 2 columns

Is there a way to check the the occurrence count of each row of pattern(dataset1) in SAX(dataset2).有没有办法检查 SAX(dataset2) 中每行模式(dataset1) 的出现次数。 Basically the number of time's a value in pattern column of(dataset1) exists in the SAX column of (dataset2)?基本上(dataset1)的模式列中的值的次数存在于(dataset2)的SAX列中吗?

Something basically like this:基本上是这样的:

dataset1=
       pattern  no. of occurrences
0    glngsyu          3
1    zicobgm          0
2    eerptow          1
.       .             .
.       .             .
.       .             .
479  lbzujtw          2

480 rows × 2 columns

Thanks.谢谢。

This should do it这应该这样做

dataset2_SAX_value_counts = dataset2["SAX"].value_counts()
dataset1["no. of occurrences"] = dataset1["pattern"].apply(lambda x: dataset2_SAX_value_counts.loc[x])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在列A和列B中查找每个值的所有出现 - How to find all occurrences for each value in column A that is also in column B 有没有办法获取列值的出现次数并附加为新列 - Is there a way to get the number of occurrences of a column value and append as new column Python / Pandas:如何在数据框中的每一列中查找特定值的出现次数? - Python/Pandas: How to find the number of occurrences of a specific value in each column a data frame? Pandas - 如何获取列中每个值的出现次数 - Pandas - How to get the number of occurrences for each value in a column 绘制列值的出现次数 - Plotting number of occurrences of column value 有没有办法从不同的数据集中找出另一列中列值的每次出现? - Is there a way to find out each occurrence of a column value in another column from a different dataset? 在Python数据框中的另一列中出现两次值之间找到一列的最小值 - find the minimum value of a column between two occurrences of a value in another column in a Python data frame 计算与另一列匹配的字符串的出现次数 - Counting number of occurrences of string matched to another column pandas groupby 和列的每个值出现的百分比 - pandas groupby and percentage of occurrences of each value of a column 熊猫计算列中每个值的出现次数 - Pandas count the occurrences of each value in column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM