how cut strings after a specific word?
You can use str.split
to split on see less
and then use str slicing to take the first part.
df['col'] = df['col'].str.split('see less').str[0]
Output:
col
0 hi there
1 today is summer,
You can use a simple regex and str.replace
:
df['col'] = df['col'].str.replace('see less.*', '', regex=True)
output:
col
0 hi there
1 today is summer,
If you also want to remove the non-letter character just before:
df['col'].str.replace(r'\W+see less.*', '', regex=True)
output:
col
0 hi there
1 today is summer
Use str.extract
:
df['col'] = df['col'].str.extract('(.*)\s*see less')
print(df)
# Output
col
0 hi there
1 today is summer,