Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a question as I am new at the NLP. I have a dataframe consists of 2 columns. The first has a sentence lets say "Hello World, how are you?" and the second column has [6,7,8,9,10] which represents the word "World" (index positions) from the first sentence. Is there any function in python which can give me the opportunity to recognize and appear the word that in each row is specified by the index numbers?

Thank you

https://ibb.co/LRnWM7G

question from:https://stackoverflow.com/questions/65645766/find-the-word-behind-the-index-numbers-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

I think it's what you need (updated according to comments)

dataframe = ["Hello World",[6,7,8,9,10]],
                    ["Hello World",[6,7,8,9]],
                    ["Hello World",[7,8,9,10]]
resultdataframe=[]

def textbyindexlist(df):
    text = df[0]
    letterindex=df[1]
    newtext=""
    for ind in letterindex:
        newtext = newtext + text[ind]
    return newtext
for i in dataframe:
    resultdataframe.append(textbyindexlist(i))
print (resultdataframe)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...