我构建了一个执行多个清理操作的函数,但是当我在对象列上运行它时,我得到属性错误:'str'对象没有属性'str'错误。为什么?
news = {'Text':['bNikeb invests in shoes', 'bAdidasb invests in t-shirts', 'dog drank water'], 'Source':['NYT', 'WP', 'Guardian']}
news_df = pd.DataFrame(news)
def string_cleaner(x):
x = x.str.strip()
x = x.str.replace('.', '')
x = x.str.replace(' ', '')
news_df['clean'] = news_df['Text'].apply(string_cleaner)
繁星coding
相关分类