pandas 数据框str.contains()和操作 [英] pandas dataframe str.contains() AND operation
本文介绍了 pandas 数据框str.contains()和操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
df(熊猫数据框)有三行.
df (Pandas Dataframe) has three rows.
some_col_name
"apple is delicious"
"banana is delicious"
"apple and banana both are delicious"
df.col_name.str.contains("apple|banana")
将捕获所有行:
"apple is delicious",
"banana is delicious",
"apple and banana both are delicious".
如何在str.contains方法上应用AND运算符,以便它仅捕获同时包含苹果&字符串的字符串.香蕉吗?
How do I apply AND operator on str.contains method, so that it only grabs strings that contain BOTH apple & banana?
"apple and banana both are delicious"
我想获取包含10-20个不同单词(葡萄,西瓜,浆果,橘子,...等)的字符串
I'd like to grab strings that contains 10-20 different words (grape, watermelon, berry, orange, ..., etc.)
推荐答案
您可以执行以下操作:
df[(df['col_name'].str.contains('apple')) & (df['col_name'].str.contains('banana'))]
这篇关于 pandas 数据框str.contains()和操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文