find the sentence structure in a column dataframe

Just remove the str conversion. In pandas you apply on the columns.

import spacy
import pandas as pd

nlp = spacy.load('en_core_web_sm',disable=['ner','textcat'])

def f(text):
    doc = nlp(text)
    pos = ""
    for token in doc:
        pos += token.pos_ + " "
    return pos

df['Structure']= df.Low_Sentences.apply(f)

FYI: You had forgotten the doc = nlp(text) line!!

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top