pandas :grep像函数 [英] Pandas: grep like function

查看:125
本文介绍了 pandas :grep像函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有像Pandas中的内置函数那样的grep,如果它有一些字符串或值,就会删除一行?
在此先感谢。

Is there a grep like built-in function in Pandas to drop a row if it has some string or value? Thanks in advance.

推荐答案

查看df ['column_label] .str
下面的示例将删除A列中保留'a'字符和'B'等于20的所有行。

Have a look at df['column_label].str Below example will drop all rows where column A holds 'a' character and 'B' equals 20.

In [46]: df
Out[46]:
     A   B
0  foo  10
1  bar  20
2  baz  30

In [47]: cond = df['A'].str.contains('a') & (df['B'] == 20)

In [48]: df.drop(df[cond].index.values)
Out[48]:
     A   B
0  foo  10
2  baz  30

这篇关于 pandas :grep像函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆