How do I extract multiple keywords on a certain descriptions

nlp keyword extraction python
multiple keyword example
keyword extraction deep learning
keyword extraction techniques
multiple keyword definition
targeting multiple keywords
keyword extraction short text
how to rank for a keyword fast

Here's my dataset

No   Description
1    Paying Google ads
2    Purchasing Facebook Ads
3    Purchasing Ads
4    AirBnB repayment

I have txt files called entity.txt

0, Google
1, Facebook
2, Ads

What I need is detect all the keyword on entity.txt in my dataframe either only single or multiple keywords and if no one keyword detected we call it Other, so My Output expectation is:

No   Description                 Keyword
1    Paying Google ads           Google
2    Purchasing Facebook Ads     Facebook Ads
3    Purchasing LinkedIn Ads     LinkedIn Ads
4    AirBnB repayment            Other

Here's what I did

with open('entity.txt') as f: 
    content = f.readlines()
content = [x.strip() for x in content ]
df['keyword'] = df['description'].apply(lambda x: ' '.join([i for i in content if i in x]))
df['keyword'] = df['keyword'].replace('', 'Other')

But, the result is

No   Description                 Keyword
1    Paying Google ads           Other
2    Purchasing Facebook Ads     Other
3    Purchasing LinkedIn Ads     Other
4    AirBnB repayment            Other

Use str.findall for extract all values from df1 to lists, then convert empty lists to Other and all filled ones join by space with str.join:

df1 = pd.DataFrame({'entity':['Google','Facebook','Ads']})

s = df['Description'].str.findall(r'({})'.format('|'.join(df1['entity'])))
df['Keyword'] = np.where(s.astype(bool), s.str.join(' '), 'Other')
print (df)

   No              Description       Keyword
0   1        Paying Google ads        Google
1   2  Purchasing Facebook Ads  Facebook Ads
2   3  Purchasing LinkedIn Ads           Ads
3   4         AirBnB repayment         Other

Your solution:

s = df['Description'].apply(lambda x: [i for i in set(df1['entity']) if i in x])
df['Keyword'] = np.where(s.astype(bool), s.str.join(' '), 'Other')
print (df)
   No              Description       Keyword
0   1        Paying Google ads        Google
1   2  Purchasing Facebook Ads  Facebook Ads
2   3  Purchasing LinkedIn Ads           Ads
3   4         AirBnB repayment         Other

Alternative:

out = []
for x in df['Description']:
    L = [i for i in set(df1['entity']) if i in x]
    if bool(L):
        out.append(' '.join(L))
    else:
        out.append('Other')
df['Keyword'] = out
print (df)
   No              Description       Keyword
0   1        Paying Google ads        Google
1   2  Purchasing Facebook Ads  Facebook Ads
2   3  Purchasing LinkedIn Ads           Ads
3   4         AirBnB repayment         Other

Here's How to Rank for Multiple Keywords with One Piece of Content, Well, targeting user intent makes it even easier to build multiple keywords into one piece Here are some additional tips you should consider when building multiple The best meta descriptions will entice people to click your link through to your It will also extract texts that are embedded within the image, using an OCR  You can use this formula to extract things like email addresses, or other substrings with a unique id. In the example shown, the formula in C5 is: = TRIM(MID(SUBSTITUTE(B5," ",REPT(" ",99)),MAX(1,FIND("@",SUBSTITUTE(B5," ",REPT(" ",99))) - 50),99)) How this formula works

Using findall

df.Description.str.findall(('|'.join(s.tolist()))).str[0]
0      Google
1    Facebook
2         Ads
3         NaN
Name: Description, dtype: object
df['Keyword']=df.Description.str.findall(('|'.join(s.tolist()))).str[0]

Data input

s
0      Google
1    Facebook
2         Ads
Name: s, dtype: object

Keyword Extraction: A Guide to Finding Keywords in Text, It also implies that the customer has been waiting for several hours. You can use a keyword extractor to pull out single words (keywords) or groups of two or more​  To count the number of specific words or keywords that appear in a given cell, you can use a formula based on the SEARCH, ISNUMBER, and SUMPRODUCT functions. In the example shown, the formula in C5 is: = SUMPRODUCT ( -- ISNUMBER ( SEARCH ( keywords

Using str.extract()

df['Keyword']=df.Description.str.extract(r'({})'.format('|'.join(df1[1],)))
print(df)

  No              Description    Keyword
0   1        Paying Google ads     Google
1   2  Purchasing Facebook Ads   Facebook
2   3  Purchasing LinkedIn Ads        Ads
3   4         AirBnB repayment        NaN

Extract multiple lines with secondary keyword search, I am not sure I understand correctly since your description of the problem does not match your desired output, but if the different entries in your file are separated​  While you can scan through job descriptions and try counting words of emphasis, there is no better or faster way to view those emphasized keywords than a good ol' word cloud. Word Clouds Are So Money Word clouds (or tag clouds) were created for the sole purpose of quickly identifying the most important terms and words of a webpage, posting, or

Advanced Data Mining and Applications: 5th International , The next section reviews some related work on keyword extraction. In section 3, a detailed description of the proposed approach is presented. Subsequently in  In Excel, you can filter the rows meeting the criteria first, and then copy them to another location. 1. Select the range included headers you want to extract rows from, click Data > Filter to add the Filter icons beside headers.

Solved: Searching For Multiple Keywords Within Rows of Tex , Solved: I have a dataset with ~300k rows that has a "Job Description" field which contains free form text entries describing construction. Lots of keyword extraction techniques are there depends on factors like: 1. Grammatical quality of text. 2. Length of text 3. Are you looking for a single keyword or phrasal keyword etc.

Extract Title Tag and Meta Description from URLs, Extract Page Title, Description and Keywords from URLs. Enter a list of URLs and this tool will return the title tag, keywords and description for them  Stephen, you don't have to use a formula to extract records where column 4 is equal to A. 1. Select the range you want to filter 2. Go to tab "Home" on the ribbon 3. Click "Sort & Filter" button 4. Click the arrow in column 4 and only select "A" Now you can copy filtered rows to sheet2. However, if you do want to use a formula this post

Comments
  • what is s, can you elaborate?
  • @NabihBawazir your text file entity.txt
  • Sorry, it is not working if we have multiple keyword in one description
  • How about multiple keyword in one description ?
  • @NabihBawazir didnt get it sorry, you mean you want to map multiple keywords for each row? if so how? can you add a sample please?