[英]Replacing strings in one column with the details of another column in a single dataframe
您可以使用str.split
在' - '
上拆分,然后只保留第二部分:
# replace colA & colB by real column names
df['colA'] = df['colB'].str.split(' - ').str[1]
在-
之后使用Series.str.extract
作為值:
df['colA'] = df['colB'].str.extract('\s+-\s+(.*)', expand=False)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.