【发布时间】:2021-08-02 11:47:28
【问题描述】:
此代码用于旧版 pandas (0.24.2),但在当前版本 (1.3.0) 中引发错误:*ValueError: Series.replace cannot use dict-like to_replace and non-None value*。
import pandas as pd
a = pd.DataFrame([['the quick red fox jumps over the lazy dog','red|over'],['red is the color for danger','red']], columns=['text','match'])
a['text'].replace(r'('+a['match']+')', r'<*\1*>', regex=True, inplace=True)
print(a)
如何让它在较新的版本上运行?
【问题讨论】: