我有以下代码:
import spacy
from spacy import displacy
from pathlib import Path
nlp = spacy.load('en_core_web_sm', parse=True, tag=True, entity=True)
sentence_nlp = nlp("John go home to your family")
svg = displacy.render(sentence_nlp, style="dep", jupyter=True)
output_path = Path("/images/dependency_plot.svg")
output_path.open("w", encoding="utf-8").write(svg)
Run Code Online (Sandbox Code Playgroud)
我正在尝试将渲染文件写入图像文件夹中的 svg 文件。但是,我收到错误:
回溯(最近一次调用最后一次):
文件 "",第 8 行,在 output_path.open("w", encoding="utf-8").write(svg)
文件“C:\Users****\AppData\Local\Continuum\miniconda3\lib\pathlib.py”,第 1183 行,在 open opener=self._opener 中)
文件“C:\Users****\AppData\Local\Continuum\miniconda3\lib\pathlib.py”,第 1037 行,在 _opener 中返回 self._accessor.open(self, flags, mode)
文件“C:\Users****\AppData\Local\Continuum\miniconda3\lib\pathlib.py”,第 387 行,包装返回 strfunc(str(pathobj), *args) FileNotFoundError: [Errno 2] 没有这样的文件或目录:'\images\dependency_plot.svg'
该目录确实存在,所以我不确定我做错了什么。我还查看了 spacy 使用页面https://spacy.io/usage/visualizers#jupyter并无法弄清楚我做错了什么。我正在使用 spyder(如果需要此信息)。请协助。
假设我有这样的代码:
For Each cell1 In range_vals
For Each cell2 In range_pred
If (cell1 = cell2) Then
//Do something
End If
Next cell1
Next cell2
Run Code Online (Sandbox Code Playgroud)
但我想做的是同时迭代两个单元格范围,并且这个范围的长度,如下所示:
For Each cell1, cell2 In range_vals, range_pred
If (cell1 = cell2) Then
//Do something
End If
Next cell1, cell2
Run Code Online (Sandbox Code Playgroud)
我知道这可以在 python 中完成,但是我在 VBA 中很难做到这一点。
我正在尝试编写一个测试模块来测试我在VBA中编写的模块之一.具体来说,我有一个if语句,我希望通过给模块/功能提供错误的初始参数来触发测试模块.我想测试的模块/功能是:
Function TPR_TNR_FPR_FNR(expected_vals As Range, pred_vals As Range,
val_tested As Integer) As Double
If WorksheetFunction.CountA(expected_vals) <>
WorksheetFunction.CountA(pred_vals) Then
MsgBox "Cells in Expected_vals and pred_vals must be the same in length"
Stop
End If
count_all = 0
For Each cell In expected_vals
If cell = val_tested Then
count_all = count_all + 1
End If
Next cell
count_correct = 0
For i = 1 To expected_vals.Cells.Count
If (expected_vals.Cells(i).Value = pred_vals.Cells(i).Value) And
(expected_vals.Cells(i).Value = val_tested) Then
count_correct = count_correct + 1
End If …Run Code Online (Sandbox Code Playgroud) accounts = pd.read_csv('C:/*******/New_export.txt', sep=",", dtype={'number': object})
accounts.columns = ["Number", "F"]
for i, j in accounts["Number"].iterrows(): #i represents the row(index number), j is the number
if (str(j) == "27*******5"):
print(accounts["F"][i], accounts["Number"][i])
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
AttributeError:“系列”对象没有属性“ iterrows”
我不太了解该错误,因为“帐户”是一个熊猫数据框。请协助。
如果我有一个看起来像这样的数据框:
from pandas import DataFrame as df
data_df = df(data={"Number": [234, 7892, 109736, 8384664088]})
print(data_df)
Number
0 234
1 7892
2 109736
3 8384664088
Run Code Online (Sandbox Code Playgroud)
如何使用特定字符快速将数据框中的条目扩展为具有最大长度的条目的长度?例如,如果我使用“#”将它们扩展为:
Number
0 234#######
1 7892######
2 109736####
3 8384664088
Run Code Online (Sandbox Code Playgroud) 我已经训练了一个 keras 模型并将其保存以供以后进行预测。但是,我使用以下方法加载了保存的模型:
from keras.models import load_model
#Restore saved keras model
restored_keras_model = load_model("C:/*******/saved_model.hdf5")
Run Code Online (Sandbox Code Playgroud)
现在我想保存加载模型的图像,以便在进行预测之前可以在使用它之前对其进行可视化。
有没有办法在 keras 中做到这一点,或者是否需要使用另一个库?
我试图从列表列表(带有字符串条目)中删除所有 nan,我的数据如下:
[['beer', 'nuts', nan],
['beer', 'butter', 'apple'],
['beer', 'nuts', 'cheese'],
['beer', 'bananas', nan],
['beer', 'nuts', 'apple']]
Run Code Online (Sandbox Code Playgroud)
我想得到这个结果:
[['beer', 'nuts'],
['beer', 'butter', 'apple'],
['beer', 'nuts', 'cheese'],
['beer', 'bananas'],
['beer', 'nuts', 'apple']]
Run Code Online (Sandbox Code Playgroud)
我尝试从(如何从列表列表中删除 nan?[重复] 和如何从列表列表中删除 [NaN]?)中得到答案,即:
import math
nan = float('nan')
store_data_list = [[x for x in y if not math.isnan(x)] for y in store_data_list] #remove nans from list of lists
#AND
store_data_list = [xs for xs in store_data_list if not any(math.isnan(x) for x in xs)]
#AND
store_data_list …Run Code Online (Sandbox Code Playgroud) python ×3
excel ×2
loops ×2
pandas ×2
python-3.x ×2
vba ×2
dataframe ×1
excel-vba ×1
keras ×1
list ×1
rubberduck ×1
spacy ×1
tensorflow ×1