這是代碼:
data = { title:["[US]Tomorrow Never Dies", "[CA]Stories We Tell"]}
df["Country", "Title"] = df['a'].str.split("[ ]", n = 1, expand = True)
我試圖讓它看起來像這樣
Country Title
[US] Tomorrow Never Dies
[CA] Stories We Tell
uj5u.com熱心網友回復:
我們可以str.extract在這里使用:
df["Country"] = df["Title"].str.extract(r'\[(.*?)\]')
df["Title"] = df["Title"].str.extract(r'\[.*?\]-?(.*)$')
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/358438.html
