Python中的正则表达式问题?

时间:2019-02-21 15:31:33

标签: python regex series

我有一个数据框:

df112 = pd.DataFrame({'A': ['**MDHC1235 Variance colinear', '**HINN0165 Paris Tower [HAQ] Relay Fashion', 'RJV Rust Falcon Contrast[HAQ] R/T (HQA)', 'Hulk Premiere A764FAR Quota 2112(HQA)'], 
                    'B': ['Italian Paste', 'US-AMBAS Contact Insured Person', '**ABDH1654 John and Jack', 'Romania (HQ)']})

我正在使用以下代码在任何文本和(

df112['A'] = df112['A'].str.replace("(\S)\(", "\1 (", regex=True)
df112['A'] = df112['A'].str.replace("(\S)\[", "\1 [", regex=True)

我得到的输出如下:

    A                                                        B
0   **MDHC1235 Variance colinear                        Italian Paste
1   **HINN0165 Paris Tower [HAQ] Relay Fashion          US-AMBAS Contact Insured Person
2   RJV Rust Falcon Contras [HAQ] R/T (HQA)             **ABDH1654 John and Jack
3   Hulk Premiere A764FAR Quota 211 (HQA)               Romania (HQ)

我不明白为什么“对比”一词中的“ t”和2112中的第二个“ 2”消失了

我做错什么了吗?

0 个答案:

没有答案