我有一个 Jupyter 笔记本(python),我使用 plotly express 在笔记本中绘图以进行分析。我想与非编码人员共享此笔记本,并且仍然可以使用交互式视觉效果 - 但它似乎不起作用。
我尝试遵循此处提出的建议,但即使在保存小部件状态并使用 之后nbconvert,当我打开新的 HTML 文件时,视觉效果也不可用。
绘图的示例线如下所示:
import plotly_express as px
fig = px.scatter(
df,
x='size',
y='size_y',
color='clients',
hover_data=['id'],
marginal_y="histogram",
marginal_x="histogram"
)
fig.show()
Run Code Online (Sandbox Code Playgroud) python data-visualization plotly jupyter-notebook plotly-express
我在MATLAB中编辑现有mp4视频的所有帧(在for循环中进行).在我完成编辑之后,我想将新的帧集保存到新的输出视频文件中,但是在mp4而不是.avi(这似乎是默认值).我认为更改文件名扩展名已足够,但显然不是.有任何想法吗?
newVid = VideoWriter(outputfilename);
newVid.FrameRate = fps;
newVid.Quality = 100;
open(newVid)
for...
writeVideo(newVid,imgs{i})%within the for loop saving one frame at a time
end
close(newVid)
Run Code Online (Sandbox Code Playgroud) 我有一个数据框,我想在同一单元格中合并两行的内容,并用下划线分隔。如果这是原始 DF:
0 eye-right eye-right hand
1 location location position
2 12 27.7 2
3 14 27.6 2.2
Run Code Online (Sandbox Code Playgroud)
我希望它变成:
0 eye-right_location eye-right_location hand_position
1 12 27.7 2
2 14 27.6 2.2
Run Code Online (Sandbox Code Playgroud)
最终我想将第 0 行转换为标题,并为整个 df 重置索引。
我将数据加载到 kepler.gl ( https://kepler.gl/ ) 中,并创建了一个我想通过将代码嵌入到博客文章中在线发布的视觉效果。但是,我希望读者/用户无法看到和访问侧面板,而只能看到地图的主视图。
有什么办法可以做到这一点,或者在导出 html 时可以更改任何参数吗?
当使用plotly-express(px)和plotly.offline进行绘图时,每隔一段时间(也许每小时一次)我会在浏览器上重新打开所有以前的绘图。
我尝试访问 ExpressFigure 对象以查看问题是否存在 - 但无法管理。
import plotly_express as px
from plotly.offline import plot
iris = px.data.iris()
scatter_plot = px.scatter(iris, x="sepal_width", y="sepal_length")
plot(scatter_plot)
Run Code Online (Sandbox Code Playgroud)
这将在新选项卡中绘制数据(在本地目录中保存 html 文件),该选项卡将每隔一段时间重新打开一次,重新绘制实例。
(这需要安装plotly_express和pandas。要安装px,只需运行pip install plotly_express)。
我有一个巨大的表(超过 100B 记录),我向其中添加了一个空列。如果所需的字符串可用,我会解析来自另一个字段(字符串)的字符串,从该字段中提取一个整数,并希望在具有该字符串的所有行的新列中更新它。
目前,在数据被解析并本地保存在数据帧中后,我对其进行迭代以使用干净的数据更新 Redshift 表。这大约需要 1 秒/迭代,这太长了。
我当前的代码示例:
conn = psycopg2.connect(connection_details)
cur = conn.cursor()
clean_df = raw_data.apply(clean_field_to_parse)
for ind, row in clean_df.iterrows():
update_query = build_update_query(row.id, row.clean_integer1, row.clean_integer2)
cur.execute(update_query)
Run Code Online (Sandbox Code Playgroud)
其中update_query是生成更新查询的函数:
def update_query(id, int1, int2):
query = """
update tab_tab
set
clean_int_1 = {}::int,
clean_int_2 = {}::int,
updated_date = GETDATE()
where id = {}
;
"""
return query.format(int1, int2, id)
Run Code Online (Sandbox Code Playgroud)
其中 clean_df 的结构如下:
id . field_to_parse . clean_int_1 . clean_int_2
1 . {'int_1':'2+1'}. 3 . np.nan
2 . {'int_2':'7-0'}. …Run Code Online (Sandbox Code Playgroud)