pandas dataframe/series 正则表达式使用 str.match str.contains str.extract

pandas dataframe/series 正则表达式使用 str.match str.contains str.extract

pandas.Series.str.match
Series.str.match(pat, case=True, flags=0, na=nan, as_indexer=False)[source]
Deprecated: Find groups in each string in the Series/Index using passed regular expression. If as_indexer=True, determine if each string matches a regular expression.

Parameters:
pat : string
Character sequence or regular expression
case : boolean, default True
If True, case sensitive
flags : int, default 0 (no flags)
re module flags, e.g. re.IGNORECASE
na : default NaN, fill value for missing values.
as_indexer : False, by default, gives deprecated behavior better achieved
using str_extract. True return boolean indexer.
Returns:
Series/array of boolean values
if as_indexer=True
Series/Index of tuples
if as_indexer=False, default but deprecated

Series.str.contains(pat, case=True, flags=0, na=nan, regex=True)[source]
Return boolean Series/array whether given pattern/regex is contained in each string in the Series/Index.

Parameters:
pat : string
Character sequence or regular expression
case : boolean, default True
If True, case sensitive
flags : int, default 0 (no flags)
re module flags, e.g. re.IGNORECASE
na : default NaN, fill value for missing values.
regex : bool, default True
If True use re.search, otherwise use Python in operator
Returns:
contained : Series/array of boolean values

Series.str.extract(pat, flags=0, expand=None)[source]
For each subject string in the Series, extract groups from the first match of regular expression pat.

New in version 0.13.0.

Parameters:
pat : string
Regular expression pattern with capturing groups
flags : int, default 0 (no flags)
re module flags, e.g. re.IGNORECASE
.. versionadded:: 0.18.0
expand : bool, default False
If True, return DataFrame.
If False, return Series/Index/DataFrame.
Returns:
DataFrame with one row for each subject string, and one column for
each group. Any capture group names in regular expression pat will
be used for column names; otherwise capture group numbers will be
used. The dtype of each result column is always object, even when
no match is found. If expand=False and pat has only one capture group,
then return a Series (if subject is a Series) or Index (if subject
is an Index).

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,398评论 19 139
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,447评论 0 23
  • 传说中的长岛冰茶,上了头真有点嗨,不过这次还是没有点着的勇气。 <烟> 现在的我 把现实点着 让它在我手上 噼噼啪...
    如果我是邓礼阅读 1,332评论 0 0
  • 俗话说:莲藕一身宝,秋藕最养人。初秋多吃藕能够养阴清热、润燥止渴、清心安神。今天给大家准备了四道以藕为主要食材的美...
    一生所求8阅读 2,166评论 0 0
  • C语言和OC并没有真正的Bool类型C语言的Bool类型非0即真OC语言的Bool类型是typedef signe...
    西门丨不吹雪阅读 2,801评论 0 0