【问题标题】:filter rows based on combination of words根据单词组合过滤行
【发布时间】:2018-07-31 10:59:25
【问题描述】:

我有一个数据框,其中有一列由逗号分隔的单词组成。我想用精确的单词组合过滤行

text
a,boy,and,a,girl
mummy, and, papa
teach, learn
teach, learn
teach

例如:我想要教行,只学习

【问题讨论】:

  • 您使用的是哪种语言? Python 还是 R?
  • 其中任何一个,最好是 r

标签: python r text filtering words


【解决方案1】:

试试这个

df <- data.frame(column_name = c("text", "a,boy,and,a,girl", "teach", "teach, learn"))

这给出了数据框的外观。然后您可以使用 dplyr 包进行以下过滤:

test <- df %>% filter(grepl("teach|text", column_name))

【讨论】:

  • data.frame(column_name = c("a,boy,and,a,girl", "teach", "teach, learn")) 测试 % filter(grepl( “教|文本”,列名))。这给出了“教”和“教,学”,而我只想要“教,学”
  • 你的命令的结果是 column_name 1 教 2 教,学习,而我只想教,学习
  • 如何搜索如果我同时有教、学和学,教在两个不同的行,应该是什么解决方案。作为 grepl 搜索模式。我必须同时给出两种模式还是它们的捷径
  • 试试这个:df &lt;- data.frame(column_name = c("text", "a,boy,and,a,girl", "teach", "teach, learn", "learn, teach"))test &lt;- df %&gt;% filter(grepl("teach |learn", column_name))
猜你喜欢
  • 2012-07-03
  • 1970-01-01
  • 2021-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-07
相关资源
最近更新 更多