Here is the code:
data = { title:["[US]Tomorrow Never Dies", "[CA]Stories We Tell"]}
df["Country", "Title"] = df['a'].str.split("[ ]", n = 1, expand = True)
I'm trying to make it look like this
Country Title
[US] Tomorrow Never Dies
[CA] Stories We Tell
CodePudding user response:
We can use str.extract
here:
df["Country"] = df["Title"].str.extract(r'\[(.*?)\]')
df["Title"] = df["Title"].str.extract(r'\[.*?\]-?(.*)$')