Issue
How do I create a column that starts from "\"" and ends in "]" in another column?
For example
A new_column
\\loc\ggg.x]ddj \\loc\ggg.x]
+\\lol\lll.d]aaa \\lol\lll.d]
I tried doing this
df['new_column'] = df['A'].str.split(']').str[0]
but it included unneeded text and want to only start at X (\) and end with Y ("]").
Solution
Try .str.extract
:
df["new_column"] = df["A"].str.extract(r"(\\.*?\])")
print(df)
Prints:
A new_column
0 \\loc\ggg.x]ddj \\loc\ggg.x]
1 +\\lol\lll.d]aaa \\lol\lll.d]
2 \\ddf\gdd\Ps\s\3\s[a.xls]ss'!e+'\\d\\P\2\d[d.xls]Canjet'!B42+'\\df\gds\+'\\s\P[s.pdf] \\ddf\gdd\Ps\s\3\s[a.xls]
Answered By - Andrej Kesely
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.