Advertisement
elena1234

how to slice string column in data frame in Python

Dec 1st, 2022 (edited)
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | Source Code | 0 0
  1. def strip_word(s:str):
  2.     ''' function to strip parts of word '''
  3.  
  4.     # n is the start position
  5.     n = s.find('/')
  6.     n = n+2 # adjust for spaces
  7.  
  8.     # m is the end position
  9.     m = s.find(') ')
  10.     m = m+1 # adjust for zero index
  11.  
  12.     s_new = s[n:m]
  13.  
  14.     return s_new
  15.  
  16.  
  17. df['Track3'] = df['menu_hint'].apply(strip_word)
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement