Pandas: grep like function

前提是你 提交于 2019-12-31 19:22:00

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/12625650/pandas-grep-like-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!