无法使用类型对象Dask执行STD

发布于 2025-01-26 18:10:17 字数 554 浏览 4 评论 0原文

在DASK上执行正常计算给我错误的

x_std = x.std().compute()

计算头:

x.head()

    LocalTime               Ask     Bid
0   2004.10.25 00:01:01.975 86.837  86.877
1   2004.10.25 00:01:19.300 86.791  86.891
2   2004.10.25 00:01:30.759 86.812  86.842
3   2004.10.25 00:01:41.798 86.801  86.831
4   2004.10.25 00:01:42.213 86.794  86.824

错误:

TypeError: cannot perform std with type object

我是按照文档进行的...

performing normal calculation on dask is giving me the error

x_std = x.std().compute()

Computing head:

x.head()

    LocalTime               Ask     Bid
0   2004.10.25 00:01:01.975 86.837  86.877
1   2004.10.25 00:01:19.300 86.791  86.891
2   2004.10.25 00:01:30.759 86.812  86.842
3   2004.10.25 00:01:41.798 86.801  86.831
4   2004.10.25 00:01:42.213 86.794  86.824

Error :

TypeError: cannot perform std with type object

I was doing in accordance with documentation ...

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

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

发布评论

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

评论(1

花辞树 2025-02-02 18:10:17

x.head()的输出中,可以看出其中一列是DateTime列,但是没有转换,它可能被存储为>“ object”列。要检查dtypes,请运行:

print(ddf.dtypes)

要转换,使用此博客文章

from dask.dataframe import to_datetime

# note this overwrites the original column
ddf["LocalTime"] = to_datetime(ddf["LocalTime"])

如果其他两个列(询问和投标)也是对象,则需要另一种转换为数字(请参见此博客文章有关详细信息):

from dask.dataframe import to_numeric

ddf["Ask"] = to_numeric(ddf["Ask"], errors="coerce")
ddf["Bid"] = to_numeric(ddf["Bid"], errors="coerce")

转换后,ddf_std = ddf.std()。compute()应无错误地工作。

From the output of x.head(), it can be seen that one of the columns is a datetime column, however without conversion, it's likely stored as an object column. To check dtypes, run:

print(ddf.dtypes)

To convert, use dd.to_datetime as explained in this blog post:

from dask.dataframe import to_datetime

# note this overwrites the original column
ddf["LocalTime"] = to_datetime(ddf["LocalTime"])

If the other two columns, Ask and Bid, are also objects, then another conversion, to numeric, is needed (see this blog post for details):

from dask.dataframe import to_numeric

ddf["Ask"] = to_numeric(ddf["Ask"], errors="coerce")
ddf["Bid"] = to_numeric(ddf["Bid"], errors="coerce")

After conversion, the ddf_std = ddf.std().compute() should work without error.

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