How can remove after specific text..?
ex) text(Column name) abc__22 E_abcd dcba dsdvs bfbfdd__23 dsfbbb sdfdf
so I want to erase everything after that, including particular text(__)
text(Column name) abc E_abcd dcba dsdvs bfbfdd dsfbbb sdfdf
please reply it.. if you have enough time for me.. thanks a lot
CodePudding user response:
You can use lambda and split to get results. Here is the example
df
Courses
0 Spark__12
1 Py_Spark__33
output:
df["new_column"]=df["column"].apply(lambda x:x.split("__")[0])
>>> df
Courses new_column
0 Spark__12 Spark
1 Py_Spark__33 Py_Spark
CodePudding user response:
the easiest method:
text = “hi_hello”
# i wanna del all texts after hi so result might be hi, using selector method
print(text[0:2])
# output : hi
text = “handsome! Hi”
print(text[0:9])
# output : handsome!