我已经阅读了许多其他 stackoverflow 答案,但还没有找到令人满意的答案,但之前有人问过。当我尝试使用 PyPDF2 阅读 pdf 文档时,它会将句子中的所有单词合并为一个连续的字符串。有没有人在弄清楚如何避免这种情况方面取得任何进展。下面是代码
import PyPDF2
import pandas as pd
import struct as struct
from nltk import word_tokenize
pdfFileObj = open("notes.pdf", 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
## reading pages fine
print(type(pdfReader.numPages))
## read in the pages
pageObj = pdfReader.getPage(0)
print(pageObj.extractText())
下面是输出示例
2)Explanationofthedifferencebetweenprobabilityandstatistics.Theroleofprobability
instatisticaldecisionmaking.ExamplesoftheuseofProbabilityinStatistics.
3)Datasummarization(graphicalandnumerical)
4)Probabilityandrandomvariables