Python Pandas:如何在列中搜索字符串? [英] Python Pandas: How can I search for a string in a column?
本文介绍了Python Pandas:如何在列中搜索字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的DataFrame:
I have a DataFrame like this:
col1,col2
Sam,NL
Man,NL-USA
ho,CA-CN
我想选择第二列包含单词"NL"的行,这类似于SQL like
命令.有人知道Python Pandas中有类似的命令吗?
And I would like to select the rows whose second column contains the word 'NL', which is something like SQL like
command. Does anybody know about a similar command in Python Pandas?
推荐答案
答案是这里.让df
作为您的DataFrame.
The answer is here. Let df
be your DataFrame.
df[df['col2'].str.contains('NL')]
这将选择所有包含"NL"的记录.
This will select all the records that contain 'NL'.
这篇关于Python Pandas:如何在列中搜索字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文