gpt4 book ai didi

python - 将 alt.Chart() 与来自 google drive url 链接的数据一起使用

转载 作者:行者123 更新时间:2023-12-04 17:37:07 25 4
gpt4 key购买 nike

我正在 google colab 中使用 altair 进行绘图。我遇到了“最大行”警告:https://altair-viz.github.io/user_guide/faq.html#maxrowserror-how-can-i-plot-large-datasets .
这是我的数据集的头部:df.head()
所以现在我想通过 URL 传递数据,喜欢我的 googleDrive:
首先我将文件导出到我的驱动器:

"change directory and export whole csv "
os.chdir(Directory.table_dir)
one.to_json('one.json', orient='records')
然后我尝试使用 URLData 方法: https://altair-viz.github.io/user_guide/generated/core/altair.UrlData.html#altair.UrlData
os.chdir(Directory.table_dir)
#checking if i can read the file to a pandas dataframe
df=pd.read_json('one.json', orient='records')

source=alt.UrlData('content/gdrive/My Drive/SCTFT/Tables/one.json')


chart = alt.Chart(source).mark_point().encode(
x='VG:Q',
y='absID:Q',
color='file:N',
)
chart
我也试过:
source='content/gdrive/My Drive/SCTFT/Tables/one.json'
使用 df 从 matplotlib 绘图。
但从 altair 我得到:
altair plot
我没有收到错误消息。
我应该改变我导出文件的方式吗?或者我如何将它与 URL 链接?
使用新信息进行编辑
我运行了来自 https://colab.research.google.com/github/altair-viz/altair_data_server/blob/master/AltairDataServer.ipynb 的代码
: pip install
first graph
它一直有效,直到:
Altair data server
这只是我在没有做任何更改的情况下运行笔记本,所以我的 colab 的设置方式一定有问题吗?

最佳答案

您传递给图表的 URL 数据必须通过 HTTP 请求对前端可见,并且 content/gdrive/My Drive/SCTFT/Tables/one.json看起来不是一个有效的 URL。

由于您的数据位于 Google 驱动器上并且无法通过 HTTP URL 获得,我建议 disabling the maximum rows check并将数据框直接传递给图表:

alt.data_transformers.enable(max_rows=None)

alt.Chart(df).mark_point().encode(
x='VG:Q',
y='absID:Q',
color='file:N',
)

关于python - 将 alt.Chart() 与来自 google drive url 链接的数据一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56212505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com