用户警告:此模式被解释为正则表达式,并且具有匹配组

发布于 2025-01-12 13:47:28 字数 2017 浏览 1 评论 0原文

给定以下 pandas DataFrame -

json_path报告组实体/分组实体 ID调整值(今天,无 Div,美元)调整后的 TWR(本季度,无 Div,美元)调整后的 TWR(年初至今,无 Div,美元)年化调整后的 TWR(自成立以来,无 Div,美元)调整值(无 Div,美元)TWR 审计说明
data.attributes.total.children。[0 ].孩子们。[0].孩子们。[0]巴拉克家族威廉和鲁珀特信托9957007-1.44-1.44
data.attributes.total.children.[0].children.[0].children.[0].children.[0]兵营家庭现金--1.44-1.44
data.attributes.total.children.[0].children.[0].children.[1]Barrack FamilyGratia Holdings No. 2 LLC841365555491732.66-0.971018847-0.97101884711.5249030955491732.66
data.attributes.total.children.[0].children.[0].children.[1].children.[0]Barrack Family投资级固定收益-18469768.618469768.6
data.attributes.total.children.[0].children.[0].children.[1].children.[1]Barrack Family高收益固定收益-3668982.44-0.205356545-0.2053565454.4411901273668982.44

我尝试使用以下语句仅保存包含 4 次 .children.[] 出现的行 -

代码: perf_by_entity_df = df[df['json_path'].str.contains(r'(\.children\.\[\d+\]){4}')]

但是收到以下内容:

错误:用户警告:此模式被解释为正则表达式,并且具有匹配组。要实际获取组,请使用 str.extract。

对于为什么会发生这种情况有什么建议吗?

Given the following pandas DataFrame -

json_pathReporting GroupEntity/GroupingEntity IDAdjusted Value (Today, No Div, USD)Adjusted TWR (Current Quarter, No Div, USD)Adjusted TWR (YTD, No Div, USD)Annualized Adjusted TWR (Since Inception, No Div, USD)Adjusted Value (No Div, USD)TWR Audit Note
data.attributes.total.children.[0].children.[0].children.[0]Barrack FamilyWilliam and Rupert Trust9957007-1.44-1.44
data.attributes.total.children.[0].children.[0].children.[0].children.[0]Barrack FamilyCash--1.44-1.44
data.attributes.total.children.[0].children.[0].children.[1]Barrack FamilyGratia Holdings No. 2 LLC841365555491732.66-0.971018847-0.97101884711.5249030955491732.66
data.attributes.total.children.[0].children.[0].children.[1].children.[0]Barrack FamilyInvestment Grade Fixed Income-18469768.618469768.6
data.attributes.total.children.[0].children.[0].children.[1].children.[1]Barrack FamilyHigh Yield Fixed Income-3668982.44-0.205356545-0.2053565454.4411901273668982.44

I try and save only rows that contain 4x occurances of .children.[] using the following statement -

Code: perf_by_entity_df = df[df['json_path'].str.contains(r'(\.children\.\[\d+\]){4}')]

However receive the following:

Error:UserWarning: This pattern is interpreted as a regular expression, and has match groups. To actually get the groups, use str.extract.

Any suggestions why this is happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留一抹残留的笑 2025-01-19 13:47:28

使用下面的代码来抑制警告:

perf_by_entity_df = df[df['json_path'].str.contains(r'(?:\.children\.\[\d+\]){4}')]

Replace:

r'(\.children\.\[\d+\]){4}'

By:

r'(?:\.children\.\[\d+\]){4}'
#  ^^-- HERE: Non capturing group

来自 文档< /a>:

(?:...)

常规括号的非捕获版本。匹配括号内的任何正则表达式,但执行匹配后无法检索该组匹配的子字符串,也无法稍后在模式中引用该子字符串。

Use the code below to suppress the warning:

perf_by_entity_df = df[df['json_path'].str.contains(r'(?:\.children\.\[\d+\]){4}')]

Replace:

r'(\.children\.\[\d+\]){4}'

By:

r'(?:\.children\.\[\d+\]){4}'
#  ^^-- HERE: Non capturing group

From the documentation:

(?:...)

A non-capturing version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文