[英]Extract partial string after a specific character and place in new column
I have a df in which I want to strip a string up to a certain character and then create a new column out of it. 我有一个df,其中我想将字符串剥离成某个字符,然后从中创建一个新列。
a
John/Smith
becomes 变成
a b
John /Smith
Thanks. 谢谢。
Use str.split
使用
str.split
Ex: 例如:
import pandas as pd
df = pd.DataFrame({"a": ["John/Smith"]})
df[["a", "b"]] = df["a"].str.split("/").apply(pd.Series)
print(df)
Output: 输出:
a b
0 John Smith
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.