首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用python中的word tokenize函数删除列表中的编号?我正在获得输出,但我需要不带数字的输出

如何使用python中的word tokenize函数删除列表中的编号?我正在获得输出,但我需要不带数字的输出
EN

Stack Overflow用户
提问于 2020-05-01 16:33:38
回答 1查看 84关注 0票数 0

我不需要列表编号(即) 0,1等。我需要打印没有编号的元素

代码语言:javascript
复制
    import pandas as pd
    from nltk.tokenize import word_tokenize
    import csv
    # define punctuation
    my_str=pd.read_csv("ef.csv")
    punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~...'''
    word_tokens = word_tokenize(str(my_str))
    #mystr=str(my_str)
    # remove punctuation from the string
    no_punct = [char for char in word_tokens if not char in punctuations]
    no_punct=[]
    for char in word_tokens:
      if char not in punctuations:
          #no_punct = no_punct + char
           no_punct.append(char)

如何使用python中的word tokenize函数删除列表中的编号?我正在获得输出,但我需要不带数字的输出

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-02 10:53:07

嗯,这可以使用简单的python来完成...

代码语言:javascript
复制
sentence=['Raghavan', 'teaching', 'is', 'excellent', '0', 'Sankar', 'is', 'good', 'at', 'teaching', '1', 'Darwin', 'is', 'extraordinary', 'in', 'teaching']
for i in sentence:
    try:
        if str(int(float(i))).isnumeric():
            sentence.remove(i)
    except:
        pass
print(sentence)
# output - ['Raghavan', 'teaching', 'is', 'excellent', 'Sankar', 'is', 'good', 'at', 'teaching', 'Darwin', 'is', 'extraordinary', 'in', 'teaching']
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61539180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档