设定
具有以下结构形式的字典:
subnetwork_dct = {518418568: {2: (478793912, 518418568, 518758448),
3: (478793912, 518418568, 518758448, 1037590624),
4: (478793912, 518418568, 518758448, 1037590624)},
552214776: {2: (431042800, 552214776),
3: (431042800,)},
993280096: {2: (456917000, 993280096),
3: (456917000, 993280096),
4: (456917000, 993280096)}}
Run Code Online (Sandbox Code Playgroud)
预期产量
遵循以下架构的Pandas DataFrame:
0 1 2
518418568 2 478793912
518418568 2 518418568
518418568 2 518758448
518418568 3 478793912
518418568 3 518418568
518418568 3 518758448
518418568 3 1037590624
518418568 4 478793912
518418568 4 518418568
518418568 4 518758448
518418568 4 1037590624
552214776 2 431042800
552214776 2 552214776 …
Run Code Online (Sandbox Code Playgroud) 我plotly==4.5.1
在jupyter==1.0.0
笔记本中使用,python==3.7.4
.
之前显示的同一段代码:
现在显示这个,没有任何修改:
有没有人对为什么会这样有任何见解?这与 plotly 的在线/离线模式有关吗?
为了完整起见,这里是一些示例虚拟数据
df_heat = pd.DataFrame({'lat': {0: -62.884215, 1: -62.834226, 2: -62.811707, 3: -62.744564, 4: -62.704835},
'lon': {0: 39.4402361, 1: 39.4080722, 2: 39.3804616, 3: 39.4891116, 4: 39.4243305},
'count': {0: 1, 1: 1, 2: 1, 3: 1, 4: 1}})
Run Code Online (Sandbox Code Playgroud)
以及用于创建地图的代码。
import plotly.graph_objects as go
fig = go.Figure(go.Densitymapbox(lat=df_heat['lat'], lon=df_heat['lon'], z=df_heat['count'],
radius=10,))
fig.update_layout(mapbox_style="carto-positron", mapbox_zoom=10, mapbox_center = {"lat": 40.7831, "lon": -73.9712},)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
Run Code Online (Sandbox Code Playgroud)
重新启动我的计算机似乎解决了这个问题¯\_(?)_/¯。对它为什么发生的洞察力仍然会受到赞赏。
问题
我正在尝试使用 PyTorch 加载文件,但错误状态archive/data.pkl
不存在。
代码
import torch
cachefile = 'cacheddata.pth'
torch.load(cachefile)
Run Code Online (Sandbox Code Playgroud)
输出
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-4-8edf1f27a4bd> in <module>
1 import torch
2 cachefile = 'cacheddata.pth'
----> 3 torch.load(cachefile)
~/opt/anaconda3/envs/matching/lib/python3.8/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
582 opened_file.seek(orig_position)
583 return torch.jit.load(opened_file)
--> 584 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
585 return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
586
~/opt/anaconda3/envs/matching/lib/python3.8/site-packages/torch/serialization.py in _load(zip_file, map_location, pickle_module, **pickle_load_args)
837
838 # Load the data (which may in turn use `persistent_load` to load tensors) …
Run Code Online (Sandbox Code Playgroud) 我想向一个顶点添加多个属性,但从一开始就没有明确知道这些属性可能是什么。例如,假设将一个人作为顶点添加到图中,我们有以下属性字典:
人 1
{
"id": 1,
"first_name": "bob",
"age": 25,
"height": 177
}
Run Code Online (Sandbox Code Playgroud)
也许要添加另一个顶点,一个人具有以下属性:
人 2
{
"id": 2,
"first_name": "joe",
"surname": "bloggs",
"occupation": "lawyer",
"birthday": "12 September"
}
Run Code Online (Sandbox Code Playgroud)
有没有办法将两个人都添加到图中,而无需将属性键和值显式硬编码到 Gremlin属性函数中?
此链接提供了正确方向的答案。可在此处找到更多有用信息。以下行反映了建议的解决方案,按预期执行,并将新顶点添加到图中。伟大的。
g.addV("person").property("id", 1, "first_name", "bob", "age", 25, "height", 177).next()
Run Code Online (Sandbox Code Playgroud)
但是,它仅在输入是硬编码的情况下才寻求工作。我已将属性字典转换为 (k1, v1, k2, v2, ..., kn, vn) 形式的值元组,但我无法以编程方式传递值。例如
tup_vals = ("id", 1, "first_name", "bob", "age", 25, "height", 177)
Run Code Online (Sandbox Code Playgroud)
但无论出于何种原因,我都不能打电话:
g.addV("person").property(*tup_vals).next()
Run Code Online (Sandbox Code Playgroud)
上面的行不会抛出异常,它只是没有按预期执行(即没有传入属性)
有没有人对如何以计算方式将这些属性字典传递给 Gremlin 属性函数有任何见解?
更新:幼稚/低效的解决方案
下面提供了一个解决方案,但这是一个糟糕的解决方案,因为它每次迭代都会查询 gremlin 服务器。理想情况下,我想同时添加所有属性。并且只有在 id 是唯一的情况下才能真正按预期工作。
g.addV("person").property('id', id).next()
for …
Run Code Online (Sandbox Code Playgroud) 我正在努力将我编写的这段代码(构造静态热图)转换为带有日期滑块的动画版本。
import pandas as pd
import plotly.graph_objects as go
...
fig = go.Figure(go.Densitymapbox(lat=df_heat['lat'], lon=df_heat['lon'], z=df_heat['count'],
radius=10,))
fig.update_layout(mapbox_style="carto-positron", mapbox_zoom=10, mapbox_center = {"lat": 40.7831, "lon": -73.9712},)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
Run Code Online (Sandbox Code Playgroud)
上面的代码成功地将 Pandas DataFrame df_heat
(如下所示)转换为 Plotly heatmap。
lat lon count
0 -62.884215 39.440236 1
1 -62.834226 39.408072 1
2 -62.811707 39.380462 1
3 -62.744564 39.489112 1
...
Run Code Online (Sandbox Code Playgroud)
静态热图输出:
df_heat
本身只是以下 DataFrame 的聚合视图,其中还包括日期。
date lat lon count
0 2018-07-29 40.691828 -73.944609 1
1 2018-07-29 40.693601 -73.945092 1
2 2018-07-29 40.696132 -73.945178 …
Run Code Online (Sandbox Code Playgroud) 我想在 groupby 之后ffill
添加一个特定的列。bfill
我的解决方案有效:
import numpy as np
import pandas as pd
df = pd.DataFrame({
"A": [1, 1, 1, 1, 2, 2, 2, 2],
"B": [np.nan, 'f1', 'b1', np.nan, np.nan, 'f2', 'b2', np.nan]
})
df['B'] = df.groupby('A')['B'].apply(lambda _: _.ffill().bfill())
Run Code Online (Sandbox Code Playgroud)
所以这:
A B
0 1 NaN
1 1 f1
2 1 b1
3 1 NaN
4 2 NaN
5 2 f2
6 2 b2
7 2 NaN
Run Code Online (Sandbox Code Playgroud)
就变成这样了:
A B
0 1 f1
1 1 f1
2 1 …
Run Code Online (Sandbox Code Playgroud) 我相信我可以成功地将二进制数据编码为二维码,但我很难解码该数据。
这个问题的最佳答案表明 QR 码阅读器通常在解码二进制数据时遇到问题:
问题出在解码上。因为大多数解码器会尝试将其解释为文本。但由于它是二进制数据,因此您不应尝试将其作为文本处理。即使您认为可以将其从文本转换为二进制,正如您所看到的,这可能会导致值不是有效文本的问题。
对于 Python 包来说,这有多真实?我尝试过使用pyzbar
and opencv
,但没有成功(它们对于utf-8
字符串工作得很好)。我也在努力寻找 pyzbar 的有用文档,而 opencv 的文档却没有什么成果。
为了完整起见,下面是我创建的一个 QR 码示例。
data = b'\x00\x00\x00\x00\x00\x00\x00\x00\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00\x84\x00\x03\x02\x02\n\n\n\n\n\n\n\n\n\n\n\n\x08\x08\n\n\n\n\x08\x08\n\x08\x08\x08\x08\x08\x08\x08\x08\x08\n\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\n\x08\x08\x08\x08\n\n\n\x08\x08\r\r\n\x08\r\x08\x08\n\x08\x01\x03\x04\x04\x06\x05\x06\n\x06\x06\n\x0f\x0e\x0b\r\x0f\x0f\x0f\x0f\x10\x10\x0f\x0f\x0f\x0f\x0f\x0f\x0f\r\r\r\x0f\r\x0f\x0f\x0f\r\r\r\r\x0f\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\xff\xc0\x00\x11\x08\x01@\x02\x00\x03\x01\x11\x00\x02\x11\x01\x03\x11\x01\xff\xc4\x00\x1d\x00\x00\x02\x03\x01\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x04\x05\x02\x03\x06\x01\x07\x00\x08\t\xff\xc4\x00C\x10\x00\x02\x01\x02\x04\x04\x03\x05\x06\x06\x01\x03\x03\x03\x05\x00\x01\x02\x11\x00\x03\x04\x12!1\x05\x06"AQaq\x07\x132\x81\xf0\x14\x91\xa1\xb1\xc1\xd1\x08\x15#B'
Run Code Online (Sandbox Code Playgroud)
为了从该字节字符串生成二维码,我使用该segmo
库,如下所示:
qr = segno.make(data)
qr.save(path/to/output/file)
Run Code Online (Sandbox Code Playgroud)
这是生成的二维码:
每当将新文件添加到特定文件夹时,我想执行谷歌应用程序脚本。
\n目前我正在使用每 x 分钟运行一次的时钟触发器,但我只需要在向文件夹添加文件时运行脚本。有没有办法做到这一点?
\n与这个问题相同- 现在已经快 3 岁了。问题下面的评论指出:
\n\n\n如果这就是你所希望的,那么就没有触发因素。\n东西是如何进入文件夹的,您对此有任何控制权吗?\n\xe2\x80\x93 Jesse Scherer 2018 年 4 月 8 日 3:02
\n
我想知道这个评论是否仍然有效,如果有效,那么是否有解决方法。
\n例如,假设我有一个如下所示的 DataFrame:
df1 = pd.DataFrame({
"grp": ["a", "a", "a", "b", "b", "c", "c", "c", "d"],
"col1": ["1", "2", np.nan, "4", "5", np.nan, "6", "7", np.nan]
})
grp col1
0 a 1
1 a 2
2 a NaN
3 b 4
4 b 5
5 c NaN
6 c 6
7 c 7
8 d NaN
Run Code Online (Sandbox Code Playgroud)
对于列名为 的每个组grp
,我想删除col1
NaN所在的行。
限制是当组中有多行时我不想删除这些行。
我希望输出 DataFrame 看起来像这样。
df2 = pd.DataFrame({
"grp": ["a", "a", "b", "b", "c", "c", "d"],
"col1": ["1", "2", "4", …
Run Code Online (Sandbox Code Playgroud) 我需要将我的版本降级poetry
到 version 1.2.1
。
目前,它是1.2.2
.
>>> poetry --version
Poetry (version 1.2.2)
Run Code Online (Sandbox Code Playgroud)
我使用以下命令:
>>> curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.2.1 python3 -
Retrieving Poetry metadata
The latest version (1.2.1) is already installed.
Run Code Online (Sandbox Code Playgroud)
但我听说1.2.1
已经安装了。但诗版仍停留在原著之上。
>>> poetry --version
Poetry (version 1.2.2)
Run Code Online (Sandbox Code Playgroud)
这里给出的答案不起作用 ( poetry self update@1.2.1
) =>The command "self" does not exist.
我在这里做错了什么?
python ×9
pandas ×4
plotly ×2
python-3.x ×2
animation ×1
decoding ×1
gremlin ×1
jupyter ×1
optimization ×1
pickle ×1
pytorch ×1
qr-code ×1
tinkerpop ×1
tinkerpop3 ×1
triggers ×1