小编arr*_*vis的帖子

如何根据多列中的字符串匹配选择 Pandas 数据框中的行

我认为这个确切的问题还没有得到回答,所以这里是。

我有一个 Pandas 数据框,我想选择 A 列或 B 列中包含字符串的所有行。

假设数据框如下所示:

d = {'id':["1", "2", "3", "4"], 
    'title': ["Horses are good", "Cats are bad", "Frogs are nice", "Turkeys are the best"], 
    'description':["Horse epitome", "Cats bad but horses good", "Frog fancier", "Turkey tome, not about horses"],
   'tags':["horse, cat, frog, turkey", "horse, cat, frog, turkey", "horse, cat, frog, turkey", "horse, cat, frog, turkey"],
   'date':["2019-01-01", "2019-10-01", "2018-08-14", "2016-11-29"]}

dataframe  = pandas.DataFrame(d)
Run Code Online (Sandbox Code Playgroud)

这使:

id              title                      description               tag           date
1   "Horses are good"                  "Horse epitome" …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

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

标签 统计

dataframe ×1

pandas ×1

python ×1