我想将 pdf(一页)转换为 png 文件。我安装了 pdf2image 并收到此错误:popler 未安装在 Windows 中。
根据这个问题: Poppler in path for pdf2image,应该安装 poppler 并修改 PATH 。
我无法执行这些操作(我在正在使用的系统中没有必要的权限)。
我查看了 opencv 和 PIL,似乎都没有提供进行此转换的可能性:PIL(请参阅此处https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html?highlight= pdf#pdf)不提供阅读 pdf 的功能,只能将图像另存为 pdf。openCV 也是如此。
有什么建议如何将 pdf 转换为 png 吗?我可以安装任何 python 库,但无法触及 Windows 安装。
谢谢
我不理解python正则表达式中scape运算符\的功能以及原始字符串的r'的逻辑。一些帮助表示赞赏。
码:
import re
text=' esto .es 10 . er - 12 .23 with [ and.Other ] here is more ; puntuation'
print('text0=',text)
text1 = re.sub(r'(\s+)([;:\.\-])', r'\2', text)
text2 = re.sub(r'\s+\.', '\.', text)
text3 = re.sub(r'\s+\.', r'\.', text)
print('text1=',text1)
print('text2=',text2)
print('text3=',text3)
Run Code Online (Sandbox Code Playgroud)
该理论说:反斜杠字符('\')表示特殊形式或允许使用特殊字符而无需调用特殊含义。
就此问题末尾提供的链接而言,r'表示原始字符串,即符号没有特殊含义,它保持不变。
所以在上面的正则表达式中,我希望text2和text3是不同的,因为替换文本是'。'。在文本2中,即句点,而(原则上)文本3中的替代文本为r'。这是一个原始字符串,即应显示的字符串,反斜杠和句点。但它们的结果相同:
结果是:
text0= esto .es 10 . er - 12 .23 with [ and.Other ] here is more ; puntuation
text1= esto.es 10. er- 12.23 with [ and.Other ] here is more; puntuation
text2= esto\.es 10\. er …Run Code Online (Sandbox Code Playgroud) 有多种方法可以将 Excel 数据读取到 Python 中。Pandas 还提供了用于写入和读取的 API
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
df = pd.read_excel('File.xlsx', sheetname='Sheet1')
Run Code Online (Sandbox Code Playgroud)
效果很好。
但是:将每个工作表的表格直接访问到 pandas 数据框中的方法是什么?
上图显示了一个工作表,其中包含一个与 CELL (1,1) 分开的表。
此外,该工作表可能包含多个表(VBA 中的列表对象)。
我无法在任何地方找到将它们读入熊猫的方法。
注意1:无法修改工作簿以使所有表格都指向单元格(1,1)。注2:我想只使用pandas(如果可能的话)并尽量减少导入其他库的需要。但没有其他办法我准备使用其他lybray。无论如何,我无法使用 xlwings 进行管理。
这里看起来可以解析excel文件,但是没有为表格提供解决方案,仅提供完整的工作表。
pandas 的文档似乎没有提供这种可能性。
谢谢。
我想过滤一个数据框。生成的数据帧应包含所有行,其中任意多个列中包含列表中的任何单词。
我开始使用 for 循环,但应该有更好的 pythonic/pandonic 方式。
例子:
# importing pandas
import pandas as pd
# Creating the dataframe with dict of lists
df = pd.DataFrame({'Name': ['Geeks', 'Peter', 'James', 'Jack', 'Lisa'],
'Team': ['Boston', 'Boston', 'Boston', 'Chele', 'Barse'],
'Position': ['PG', 'PG', 'UG', 'PG', 'UG'],
'Number': [3, 4, 7, 11, 5],
'Age': [33, 25, 34, 35, 28],
'Height': ['6-2', '6-4', '5-9', '6-1', '5-8'],
'Weight': [89, 79, 113, 78, 84],
'College': ['MIT', 'MIT', 'MIT', 'Stanford', 'Stanford'],
'Salary': [99999, 99994, 89999, 78889, 87779]},
index =['ind1', …Run Code Online (Sandbox Code Playgroud) 我正在使用数据框,我必须将列转换为 int 类型
我使用以下符号:
result_df['ftmSectionId'] = result_df['ftmSectionId'].astype('int')
Run Code Online (Sandbox Code Playgroud)
DF 有几百万行,因此显然有一些值无法转换为 int (可能包括逗号或句点...)我收到错误:
ValueError: invalid literal for int() with base 10: 'not'
Run Code Online (Sandbox Code Playgroud)
现在根据这个问题: How do I fix invalidliteral for int() with base 10 error in pandas
我可以使用:
data.Population1 = pd.to_numeric(data.Population1, errors="coerce")
Run Code Online (Sandbox Code Playgroud)
这有效。
但这样我就不知道为什么我一开始就出错了。由于我正在使用的数据库的性质,我希望该特定列仅包含整数。如何查询该列以找出哪些值无法使用简单方法 .astype('int') 转换为 'int' ?
谢谢
其他可能的答案,但不重复: Unable to conversion pandas dataframe column to int variable type using .astype(int) method 这个问题解决了同样的问题,只是他们知道问题是该列包含 NaN 并且将其删除。我不知道这里有什么问题,我的目标不仅仅是转换为“int”,而是捕获问题值
我想将文本分成句子。
查看堆栈溢出我发现:
与NLTK
from nltk.tokenize import sent_tokenize
text="""Hello Mr. Smith, how are you doing today? The weathe is great, and city is awesome. The sky is pinkish-blue. You shouldn't eat cardboard"""
tokenized_text=sent_tokenize(text)
print(tokenized_text)
Run Code Online (Sandbox Code Playgroud)
与斯帕西
from spacy.lang.en import English # updated
raw_text = 'Hello, world. Here are two sentences.'
nlp = English()
nlp.add_pipe(nlp.create_pipe('sentencizer')) # updated
doc = nlp(raw_text)
sentences = [sent.string.strip() for sent in doc.sents]
Run Code Online (Sandbox Code Playgroud)
问题是 spacy 在后台必须用所谓的 create_pipe 做不同的事情。句子对于训练您自己的 NLP 词嵌入非常重要。spaCy 不直接包含开箱即用的句子标记器应该是有原因的。
谢谢。
注意:请注意,简单的 .split(.) 不起作用,文本中有几个十进制数字以及包含“.”的其他类型的标记。
我在整个文档中使用正则表达式来捕获出现此类正则表达式的范围:
import spacy
import re
nlp = spacy.load("en_core_web_sm")
doc = nlp("The United States of America (USA) are commonly known as the United States (U.S. or US) or America.")
expression = r"[Uu](nited|\.?) ?[Ss](tates|\.?)"
for match in re.finditer(expression, doc.text):
start, end = match.span()
span = doc.char_span(start, end)
# This is a Span object or None
# if match doesn't map to valid token sequence
if span is not None:
print("Found match:", span.text)
Run Code Online (Sandbox Code Playgroud)
有一种方法可以获取与文档上的正则表达式匹配相对应的范围(标记列表),即使正则表达式匹配的边界与标记边界不对应。请参阅:如何将匹配扩展到有效的标记序列?在https://spacy.io/usage/rule-based-matching
到目前为止,一切都很好。
现在我有了一个跨度集合,如何将它们转换为实体?我知道实体标尺:EntityRuler 是一个管道组件(另请参阅上面的链接),但该entityruler 将模式作为在文档中搜索的输入,而不是跨度。
如果我想在整个文档中使用正则表达式来获取集合 os spans,我想将其转换为 ents,下一步是什么?实体统治者?如何?或者是其他东西? …
我需要解析数百个具有相同结构的 XML 文件,如下所示:
\n\n<?xml version="1.0" encoding="UTF-8"?>\n <Concepts>\n <ConceptModel name="food">\n <Filters>\n <Filter type="CC"/>\n </Filters>\n <Queries>\n <Query lang="EN">(cheese, bread, wine)</Query>\n <Query lang="DE">(K\xc3\xa4se, Brot, Wein)</Query>\n <Query lang="FR">(fromaige, pain, vin)</Query>\n </Queries>\n </ConceptModel>\n </Concepts>\nRun Code Online (Sandbox Code Playgroud)\n\n我在互联网上阅读了几篇文章和帖子,如下所示,但我无法想出解决方案:
\n\n\n\n到目前为止我正在做:
\n\n\n\n<?xml version="1.0" encoding="UTF-8"?>\n <Concepts>\n <ConceptModel name="food">\n <Filters>\n <Filter type="CC"/>\n </Filters>\n <Queries>\n <Query lang="EN">(cheese, bread, wine)</Query>\n <Query lang="DE">(K\xc3\xa4se, Brot, Wein)</Query>\n <Query lang="FR">(fromaige, pain, vin)</Query>\n </Queries>\n </ConceptModel>\n </Concepts>\nRun Code Online (Sandbox Code Playgroud)\n\n这段代码似乎可以被VBA理解,但它不读取内容。循环不会被读取,这意味着(我猜)查询根本没有循环。事实证实了这一点Msgbox "how many queries" …
我提出了有关添加带有WITH索引的行的问题,但是我还不清楚在没有索引的情况下为什么/为什么发生这种情况:
columnsList=['A','B','C','D']
df8=pd.DataFrame(columns=columnsList)
L=['value aa','value bb','value cc','value dd']
s = pd.Series(dict(zip(df8.columns, L)))
df8.append(s,ignore_index=True)
df8.append(s,ignore_index=True)
Run Code Online (Sandbox Code Playgroud)
我希望这里有2X4数据帧。但是,没有添加任何值,也没有发生错误。
print(df8.shape)
#>>> (0,4)
Run Code Online (Sandbox Code Playgroud)
为什么不添加系列,为什么不出现任何错误?
如果我尝试使用LOC添加行,则会添加索引,
df8.loc[df8.index.max() + 1, :] = [4, 5, 6,7]
print(df8)
Run Code Online (Sandbox Code Playgroud)
结果:
A B C D
NaN 4 5 6 7
Run Code Online (Sandbox Code Playgroud)
我猜LOC和iLOC都不能用于添加没有索引名称的行(即Loc添加索引名称NaN,并且当索引号高于数据库行时不能使用iLoc)
我正在寻找一个正则表达式来匹配:
[文件编号] m
为了仅在 n=m 时摆脱 [文档 n]
其中 n 是任意数字
所以 [document 34] 34 将匹配但 [document 34] 45 不会,因为数字不同
到目前为止,我有这个:
import re
text = "[document 23] 23 and [document 34] 48 are white"
text = re.sub(r"(\[document \d+\] )(\d+)",r"\2. ",text)
Run Code Online (Sandbox Code Playgroud)
但这并不能保证数字相等。
任何的想法?