我需要从 pandas df 的列中提取值并将这些值保存在单独的列中。我需要抓住遵循特定模式的字符串。我的数据如下所示:
name
ADV | FashionWeek.ab
ADV | FashionWeek
ADV | ESPN.arb
ADV | ESPN.ob
ADV | ESPN
所需的输出是:
name clean_name
ADV | FashionWeek.ab FashionWeek
ADV | FashionWeek FashionWeek
ADV | ESPN.arb ESPN
ADV | ESPN.ob ESPN
ADV | ESPN ESPN
所以我必须抓住一切在我尝试之后ADV |
和之前发生的事情:.
new_df["clean_name"] = df["name"].split('|')[1].lstrip().split('.')[0]
错误:AttributeError: 'DataFrame' object has no attribute 'split'