Here is an example of my data:
import pandas as pd
data = {'Text':['This is an example,',
'Another sentence is here.',
'Lets have fun.',
'this happened weeks ago.',
'I am not sure what to put here.',
'Another fake sentence.'],
'Score':[20, 21, 19, 18, 16, 12]}
# Create DataFrame
df = pd.DataFrame(data)
data_words = {'words':['is',
'fun',
'happened',
'example'],
'frequency':[127, 112, 1234, 32]}
# Create DataFrame
df2 = pd.DataFrame(data_words)
#Final Result:
data_result = {'words':['is',
'fun',
'happened',
'example'],
'frequency':[127, 112, 1234, 32],
'Text': ['This is an example,',
'Lets have fun.',
'this happened weeks ago.',
'This is an example,']}
df_final = pd.DataFrame(data_result)
I am trying to match the df['text'] with the df2['words'] based on whether the word appears in the text. I just need one text per word, and ideally it would be based on "Score" but it's not completely necessary.
So, the final df would have columns: "Text", "Score", "words", and "frequency"