按子字符串标准过滤 Pandas DataFrame [英] Filter pandas DataFrame by substring critera

查看:27
本文介绍了按子字符串标准过滤 Pandas DataFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一列字符串值的 Pandas DataFrame.我需要根据部分字符串匹配来选择行.

I have a pandas DataFrame with a column of string values. I need to select rows based on a partial string matches.

类似这个成语

re.search(pattern, cell_in_question) 

返回一个布尔值.我熟悉 df[df['A'] == "hello world"] 的语法,但似乎无法找到一种方法来对部分字符串匹配做同样的事情说 <代码>'你好'.

returning a boolean. I am familiar with the syntax of df[df['A'] == "hello world"] but can't seem to find a way to do the same with a partial string match say 'hello'.

推荐答案

基于 github issue #620,看来您很快就可以执行以下操作了:

Based on github issue #620, it looks like you'll soon be able to do the following:

df[df['A'].str.contains("hello")]

更新:矢量化字符串方法(即 Series.str) 在 Pandas 0.8.1 及更高版本中可用.

Update: vectorized string methods (i.e., Series.str) are available in pandas 0.8.1 and up.

这篇关于按子字符串标准过滤 Pandas DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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