'How would I apply a function (in this case it is to grab keywords) to each row of a column in a df, and put it in a new column?

I have a dataframe about homologous proteins (almost 3000 of them!), which includes the description of each proteins' function. From this description I want to grab a key word from each cell and put it in a separate column. This is in order to create a classification of the proteins.

I am creating a function to extract key-words from the text of each individual row of the 'description' column, using yake!:

def generate_keyword():
kw_extractor = yake.KeywordExtractor(n=2, top=40)
keywords = kw_extractor.extract_keywords(data["description"])

    for kw in keywords:
        print(kw)

And then I am trying to put this information into a new column ('keyword') in the dataframe like so:

data["keyword"] = data["description"].apply(generate_keyword())

It then gives these two messages when I try to run it:

Warning! Exception: 'Series' object has no attribute 'split' generated by the following text: '0       Mitochondrial malate dehydrogenase;catalyzes i...

.......

TypeError: 'NoneType' object is not callable

I think the mistake is somewhere in how I'm labelling the parameters for my function, but I have no clue how to fix it. Any help is greatly appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source