How to remove all the characters before " \ "
column1
absc \ efgcvc \ Hello
hij \ klsm \ Hey
qssdrs \ uv \ yellow
I would like to have the output as below:
column1
Hello
Hey
Yellow
CodePudding user response:
Using str.replace
we can try:
df["column1"] = df["column1"].str.replace(r'^.*\\\s*', '')
CodePudding user response:
df = pd.DataFrame({'column1':['absc \ efgcvc \ Hello','hij \ klsm \ Hey','qssdrs \ uv \ yellow']})
df2 = pd.DataFrame(columns=['column1'])
for i in range (0,3,1):
a = df.iloc[i,0];
a = (a.split(' \ '))
df2 = df2.append({'column1': a[2]}, ignore_index=True)
print(df2)