UserWarning:此模式被解释为正则表达式,并具有匹配组

UserWarning: This pattern is interpreted as a regular expression, and has match groups

给出以下 pandas DataFrame -

json_path Reporting Group Entity/Grouping Entity ID Adjusted 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 Family William and Rupert Trust 9957007 -1.44 -1.44
data.attributes.total.children.[0].children.[0].children.[0].children.[0] Barrack Family Cash - -1.44 -1.44
data.attributes.total.children.[0].children.[0].children.[1] Barrack Family Gratia Holdings No. 2 LLC 8413655 55491732.66 -0.971018847 -0.971018847 11.52490309 55491732.66
data.attributes.total.children.[0].children.[0].children.[1].children.[0] Barrack Family Investment Grade Fixed Income - 18469768.6 18469768.6
data.attributes.total.children.[0].children.[0].children.[1].children.[1] Barrack Family High Yield Fixed Income - 3668982.44 -0.205356545 -0.205356545 4.441190127 3668982.44

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

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

但是收到以下内容:

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

对发生这种情况的原因有什么建议吗?

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

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

替换:

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

作者:

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

来自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.