如何使用 python 中的 word tokenize 函数删除列表中的编号?我得到了输出,但我需要没有数字
how to remove numbering in list using word tokenize function in python ? I am getting the output but i need without numbers
我不需要列表编号(即)0,1 等。我需要打印元素
没有编号
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 函数删除列表中的编号?我得到了输出,但我需要没有数字
嗯,这可以使用简单的 python...
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']
我不需要列表编号(即)0,1 等。我需要打印元素 没有编号
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 函数删除列表中的编号?我得到了输出,但我需要没有数字
嗯,这可以使用简单的 python...
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']