小编Cib*_*bic的帖子

Pandas:如果关键字出现在任何列中,请选择行

我知道有一个关于在一列中搜索字符串的相关线程(这里)但是如何在所有列中使用pd.Series.str.contains(pattern)?

df = pd.DataFrame({'vals': [1, 2, 3, 4], 'ids': [u'aball', u'bball', u'cnut', u'fball'],
'id2': [u'uball', u'mball', u'pnut', u'zball']})


In [3]: df[df['ids'].str.contains("ball")]
Out[3]:
     ids  vals
0  aball     1
1  bball     2
3  fball     4
Run Code Online (Sandbox Code Playgroud)

python string pandas

6
推荐指数
2
解决办法
1583
查看次数

标签 统计

pandas ×1

python ×1

string ×1