如何在DASK中使用多个条件的变量创建变量?

发布于 2025-02-12 00:12:05 字数 40 浏览 1 评论 0原文

我想应用与NP.SELECT类似的内容,但使用DASK函数或属性。

I would like to apply something similar to np.select but using dask functions or attributes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○愚か者の日 2025-02-19 00:12:06

因此,我假设您不仅在使用dask,还使用dask-dataframes。如果您在此处查看文档: https://docs.dask.orgg/en/最新/dataframe.html 您会发现,在DASK系列上进行索引被认为很快。因此,这样的例子

dd[dd.x>3] 

应该完美地工作。考虑到基本上使用布尔指示器来选择索引,我们可以使用乘法扩展示例。 true由a表示为零,零表示true * true * true的乘法始终等于1,而false * true * truetrue * falsefalse * false将产生零。

dd[(dd.x>3)*(dd.y<10)]

因此,应该为您提供所需的功能。

请注意,当您使用DASK DataFrames时,实际结果只能根据要求产生。因此,如果您想运行计算,链.compute在您的语句背后进行计算,所以

dd[(dd.x>3)*(dd.y<10)].compute()

我希望这会有所帮助

So I am assuming that you are not just using Dask, but Dask-Dataframes. If you look at the documentation here: https://docs.dask.org/en/latest/dataframe.html you will see that indexing over a Dask Series is considered to be fast. So an example like

dd[dd.x>3] 

Should work perfectly. Considering that basically uses a boolean indicator to select the index, we can extend the example by using the multiplication. True is represented by a 1 and False by a zero, which means that a multiplication of True * True will always equal 1, whilst False * True, True * False and False * False will yield a zero.

dd[(dd.x>3)*(dd.y<10)]

Should therefore give you the functionality that you are looking for.

Please note that when you are using Dask DataFrames, that the actual result will only be produced on request. So chain .compute behind your statement if you want to run the calculations like so

dd[(dd.x>3)*(dd.y<10)].compute()

I hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文