代码之家  ›  专栏  ›  技术社区  ›  Programmer_nltk

句子标点返回真空间

  •  0
  • Programmer_nltk  · 技术社区  · 7 年前

    我正在用熊猫写包含逗号的句子。

    lists = [sent for sent in doc.sents if ',' in sent.string.lower()]
    

    如果发现了,我可以在excel中为它返回True或False。

    =ISNUMBER(SEARCH(",", A1))
    

    我使用下面的代码提取句子并在excel中将其列为行

    sentences = [sent.string.strip() for sent in doc.sents]
    

    预计出局:

    Sentence                                 IS_comma_sent
    This sentence contains no comma.         False
    There is a , in this sentence.           True
    

    1 回复  |  直到 7 年前
        1
  •  1
  •   BENY    7 年前

    IIUC公司 str.contains

    df['Is_comma_sent']=df['Sentence'].str.contains(',')