默认情况下describe,Dask DataFrame的方法仅汇总数字列.根据文档,我应该能够通过提供include参数来获得分类列的描述.然而
df.describe(include=['category']).compute()
导致一个
TypeError: describe() got an unexpected keyword argument 'include'.
我也试过了一个不同的方法:
df.select_dtypes(include=['category']).describe().compute()
而这次我得到了
ValueError: DataFrame contains only non-numeric data.
您能否告诉我们在Dask DataFrame中总结分类列的最佳方法是什么?
我有一个multiply.py包含以下内容的文件:
from typing import NamedTuple
class Result(NamedTuple):
product: int
desc: str
def multiply(a: int, b: int) -> Result:
return Result(
product=a * b,
desc=f"muliplied {a} and {b}",
)
x=4
y=5
print(multiply(x, y))
Run Code Online (Sandbox Code Playgroud)
如果我像这样运行它,它当然会产生预期的结果:
$ python multiply.py
Result(product=20, desc='muliplied 4 and 5')
Run Code Online (Sandbox Code Playgroud)
exec不过我正在尝试使用以下函数运行它main.py:
from pathlib import Path
gl, lo = {}, {}
exec(Path("multiply.py").read_text(), gl, lo)
Run Code Online (Sandbox Code Playgroud)
这次的输出令人失望:
$ python main.py
Traceback (most recent call last):
File "main.py", line 4, in <module>
exec(Path("multiply.py").read_text(), gl, lo)
File "<string>", line …Run Code Online (Sandbox Code Playgroud) 我将以最小的例子解释我的问题.假设我有三个文件:
A.jl
module A
export Atype, f
type Atype
end
f = function(x::Atype)
println("f called with A")
end
end #module
Run Code Online (Sandbox Code Playgroud)
B.jl
module B
export Btype, f
type Btype
end
f = function(x::Btype)
println("f called with B")
end
end #module
Run Code Online (Sandbox Code Playgroud)
Main.jl
using A
using B
main = function()
x = Atype()
f(x)
end
main()
Run Code Online (Sandbox Code Playgroud)
这里我有两个版本的f功能.如果我理解正确的多次发送的想法,应该在运行时期间扣除应该使用哪个版本.因此,我预计运行Main.jl会打印出来f called with A.不幸的是,我明白了
$ julia Main.jl
ERROR: type: anonymous: in typeassert, expected Btype, got Atype
in include at /usr/bin/../lib64/julia/sys.so
in process_options at …Run Code Online (Sandbox Code Playgroud)