【发布时间】:2019-06-20 12:19:32
【问题描述】:
我在pandas 和python 有这个:
text1 text2
0 sunny This is a sunny day
1 rainy day No this day is a rainy day
我想把它改成这样:
text1 text2
0 sunny This is a day
1 rainy day No this day is a
因此,我想根据同一行的text1 从text2 中删除一些文本。
我这样做了:
df = df.apply(lambda x: x['text2'].str.replace(x['text1'], ''))
但我遇到了一个错误:
AttributeError: ("'str' object has no attribute 'str'", 'occurred at index 0')
这可能与此有关: https://stackoverflow.com/a/53986135/9024698.
什么是做我想做的最有效的方法?
【问题讨论】:
标签: python python-3.x pandas