使用 "place_with_parent_names" 列为 df1 创建"state"列。状态名称总是出现在"|Brasil|"之后,但我的输出包含 [ ]



将附加在图像下方的代码输入和输出作为图像代码输出和输入

列创建状态

根据我的指示

我正在写这个代码

# Split place_with_parent_names column by "|"
split_names = df1["place_with_parent_names"].str.split("|")
# Find index of "Brasil" in each list and add 1 to get index of state name
state_index = split_names.apply(lambda x: x.index("Brasil") + 1)
# Extract state name using state_index
df1["state"] = split_names.apply(lambda x: x[state_index.iloc[0]])

请投赞成票并支持我想是可行的

相关内容

最新更新