【问题标题】:Removing all English and other punctuation form the text file in Jupyter从 Jupyter 中的文本文件中删除所有英语和其他标点符号
【发布时间】:2021-12-25 15:02:19
【问题描述】:

我有一个文本文件,我想处理一些 NLP 任务。但我正在处理本地语言。该文件包含大量英文单词和标点符号。我想从那个文本文件中去掉所有的拉丁文和其他标点符号。使用 Jupyter 笔记本如何实现这一点 TIA

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: python text nlp jupyter


【解决方案1】:

当然,您只需使用 Python 即可完成此操作

text = "Hello, World!!"
# put everything you wish to filter out in this list
filterList = [',', '!']

filteredList = filter(lambda c: c not in filterList, text)
print(''.join(filteredList))

会给Hello World

【讨论】:

  • 如果这是一个文本文件呢?不只是文字?
  • 如果它是一个文件,您需要在文件中读取它以使其变为文本,过滤它,然后将结果写回文件。大概你需要将文件加载到内存中来训练你的模型
猜你喜欢
  • 2019-08-04
  • 1970-01-01
  • 1970-01-01
  • 2013-11-19
  • 1970-01-01
  • 1970-01-01
  • 2020-07-20
  • 1970-01-01
  • 2013-09-05
相关资源
最近更新 更多