本文介绍了将Dask标量转换为整数值(或将其保存到文本文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用dask
计算
from dask import dataframe
all_data = dataframe.read_csv(path)
total_sum = all_data.account_balance.sum()
csv文件具有名为account_balance
的列.
The csv file has a column named account_balance
.
total_sum
是一个dd.Scalar
对象,似乎很难将其更改为整数.如何获得它的整数版本?或将其保存在包含数字的.txt
文件中也是可以的.
The total_sum
is a dd.Scalar
object, which seems to be difficult to change it to integer. How to get the integer version of it? or save it in a .txt
file containing the number is also ok.
我也尝试过total_sum.compute()
.
谢谢.
推荐答案
.compute()
确实为您带来了实数,如您在本示例中看到的:
.compute()
does indeed bring you a real number, as you can see in this example:
In [18]: import dask.dataframe as dd
In [19]: d = dd.from_pandas(pd.DataFrame({'a': [3,3,3,3]}), npartitions=2)
In [20]: d.a.sum().compute()
Out[20]: 12
这篇关于将Dask标量转换为整数值(或将其保存到文本文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!