I have a pandas dataframe containing several columns including 'text', 'start', 'tend', and I want to create a new column that extracts a substring of 'text' based on the 'start' and 'tend'.
text start tend subtext
'Sample text' 2 8 'mple te'
'Sample text' 4 10 'le text'
This works:
df['subtext']= df['text'].str[2:6]
This produces 'nan' instead of text:
df['subtext']= df['text'].str[df['start']:df['tend']]
I'm guessing it has something to do with passing a series rather than a single value. Any help would be appreciated, and I'm open to another approach if this strategy is bad.