给定以下 pandas DataFrame -
| json_path | 报告组 | 实体/分组 | 实体ID | 调整后价值(今日,无 Div,美元) | 调整后的 TWR(本季度,无 Div,美元) | 调整后的 TWR(年初至今,无 Div,美元) | 年化调整后 TWR(自成立以来,无 Div,美元) | 调整值(无 Div,美元) | TWR审计记录 |
|---|---|---|---|---|---|---|---|---|---|
| data.attributes.total.children.[0].children.[0].children.[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] | 兵营家庭 | 格拉蒂亚控股第二有限责任公司 | 8413655 | 55491732.66 | -0.971018847 | -0.971018847 | 11.52490309 | 55491732.66 | |
| data.attributes.total.children.[0].children.[0].children.[1].children.[0] | 兵营家庭 | 投资级固定收益 | - | 18469768.6 | 18469768.6 | ||||
| data.attributes.total.children.[0].children.[0].children.[1].children.[1] | 兵营家庭 | 高收益固定收益 | - | 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}')]
Run Code Online (Sandbox Code Playgroud)
代替:
r'(\.children\.\[\d+\]){4}'
Run Code Online (Sandbox Code Playgroud)
经过:
r'(?:\.children\.\[\d+\]){4}'
# ^^-- HERE: Non capturing group
Run Code Online (Sandbox Code Playgroud)
从文档中:
(?:...)
常规括号的非捕获版本。匹配括号内的任何正则表达式,但在执行匹配后无法检索该组匹配的子字符串或稍后在模式中引用。
| 归档时间: |
|
| 查看次数: |
2791 次 |
| 最近记录: |