正则计数和从列打印
我试图在列中计算匹配 REGEX
并打印出发现的金额,下面的代码一直给我 0 。我觉得这不是整列的迭代吗?我的代码如下。
import re
pattern = ('/^[A-Z]{1}\d{8}$/i')
numbers = jan_df['Student Number']
iterator = re.finditer(pattern, str(numbers))
count = 0
for match in iterator:
count+=1
print(count)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
,或者,如果您打算使用更具体的正则义务,并且需要使其案例不敏感:
Notes :
...
,标志为选项,或作为inline flags((?i)...
) ){1}
在正则模式中始终是冗余的,请删除series.str.contains
返回true或false,具体取决于是否有匹配。df.loc [df [col] .str.contains(...),:]
仅返回找到匹配的那些行dataframe.shape.shape
返回数据框架,因此.shape [0]
返回行数。相关的帖子
Notes :
...
,标志为选项,或作为inline flags((?i)...
) ){1}
在正则模式中始终是冗余的,请删除series.str.contains
返回true或false,具体取决于是否有匹配。df.loc [df [col] .str.contains(...),:]
仅返回找到匹配的那些行dataframe.shape.shape
返回数据框架,因此.shape [0]
返回行数。相关的帖子
,或者,如果您打算使用更具体的正则义务,并且需要使其案例不敏感:
Notes :
...
,标志为选项,或作为inline flags((?i)...
) ){1}
在正则模式中始终是冗余的,请删除series.str.contains
返回true或false,具体取决于是否有匹配。df.loc [df [col] .str.contains(...),:]
仅返回找到匹配的那些行dataframe.shape.shape
返回数据框架,因此.shape [0]
返回行数。相关的帖子
You can use
Or, if you plan to use a more specific regex and need to make it case insensitive:
Notes:
/.../i
thing, you need...
with flags as options, or as inline flags ((?i)...
){1}
is always redundant in regex patterns, please remove itSeries.str.contains
returns True or False depending if there is a match.df.loc[df[col].str.contains(...), :]
only returns those rows where the match was foundDataframe.shape
returns the dimensions of the data frame, so.shape[0]
returns the number of rows.Related SO posts
Notes:
/.../i
thing, you need...
with flags as options, or as inline flags ((?i)...
){1}
is always redundant in regex patterns, please remove itSeries.str.contains
returns True or False depending if there is a match.df.loc[df[col].str.contains(...), :]
only returns those rows where the match was foundDataframe.shape
returns the dimensions of the data frame, so.shape[0]
returns the number of rows.Related SO posts
Or, if you plan to use a more specific regex and need to make it case insensitive:
Notes:
/.../i
thing, you need...
with flags as options, or as inline flags ((?i)...
){1}
is always redundant in regex patterns, please remove itSeries.str.contains
returns True or False depending if there is a match.df.loc[df[col].str.contains(...), :]
only returns those rows where the match was foundDataframe.shape
returns the dimensions of the data frame, so.shape[0]
returns the number of rows.Related SO posts