我一直在尝试查找数组的列数,但显然ncols、size和length函数不会产生所需的输出。
关于查找数组列数的正确方法有什么建议吗?
提前致谢。
我注意到使用加载 CSV 文件CSV.read很慢。作为参考,我附上一个时间基准示例:
using CSV, DataFrames
file = download("https://github.com/foursquare/twofishes")
@time CSV.read(file, DataFrame)
Output:
9.450861 seconds (22.77 M allocations: 960.541 MiB, 5.48% gc time)
297 rows × 2 columns
Run Code Online (Sandbox Code Playgroud)
这是一个随机数据集,与 Julia 相比,此类操作的 Python 替代品编译时间很短。既然 julia 比 python 快,为什么这个操作需要这么多时间?此外,有没有更快的替代方法来减少编译时间?
我正在用 Julia 编写代码。在这里,我有一个大小为 272x32 的数据框。我的目标是找到每列中的最小值,并将它们存储在一个包含 32 个元素的数组中。为了执行这个,我创建了一个 for 循环,迭代数据帧中的列范围。但是,在将值分配为全局值时,存储的输出只有最后一个值。但是,我希望它具有最少的列作为数组中的每个条目,我可以将其用于矩阵算术运算。
代码片段:
n = ncol(variables)
for i in 1:n
global mins = minimum(variables[!, i])
global maxs = maximum(variables[!, i])
end
Run Code Online (Sandbox Code Playgroud)
请建议解决此问题。
问候,
我正在尝试将数据集拆分为 Julia 中的训练子集和测试子集。到目前为止,我已经尝试使用MLDataUtils.jl包进行此操作,但是结果未达到预期。\n以下是我的发现和问题:
\n代码
\n# the inputs are\n\na = DataFrame(A = [1, 2, 3, 4,5, 6, 7, 8, 9, 10],\n B = [1, 2, 3, 4,5, 6, 7, 8, 9, 10],\n C = [1, 2, 3, 4,5, 6, 7, 8, 9, 10]\n )\nb = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n\nusing MLDataUtils\n(x1, y1), (x2, y2) = stratifiedobs((a,b), p=0.7)\n\n#Output of this operation is: (which is not the expectation)\nprintln("x1 is: $x1")\nx1 is:\n10\xc3\x973 DataFrame\n\xe2\x94\x82 Row \xe2\x94\x82 …Run Code Online (Sandbox Code Playgroud) 我正在尝试在交互式绘图上绘制时间序列数据,以便我可以放大数据以进行详细观察。我的基本情节的主要代码是,
using IterableTables, DataFrames, CSV, Dates, TimeSeries, Plots
myfile="test2.csv"
dmft = dateformat"d/m/yyyy HH:MM:SS"
println(dmft)
df = DataFrame(CSV.File(joinpath(@__DIR__,myfile); dateformat=dmft))
df2 = filter(row -> row[:Date] <= Dates.DateTime("2020-10-15T00:06:00"), df)
x = convert(Matrix, df[:, [:Date]])
y = convert(Matrix, df[:, [:Col3]])
Run Code Online (Sandbox Code Playgroud)
#我放置了常用的绘图函数,我已为此块删除了该函数`
请有人建议我如何在交互式绘图上绘制这两列?
先感谢您。
我正在尝试将长度(行数)不匹配的列添加到数据框中,它会引发错误,
DimensionMismatch("新列目标的长度为 60000 必须与数据框中的行数匹配 (47040000)")
我的代码片段是,
df = DataFrame(:Feature => train_x, :Target => train_y)
#train_x has 47040000 rows
#train_y has 60000 rows
Run Code Online (Sandbox Code Playgroud)
请为这个问题提出一个解决方案。先感谢您。
我在向 Julia 添加包时遇到错误:
\n数据框
\n(@v1.5) pkg> add DataFrames\n Updating registry at `C:\\Users\\.julia\\registries\\JuliaComputingRegistry`\n Resolving package versions...\nERROR: Unsatisfiable requirements detected for package DataFramesMeta [1313f7d8]:\n DataFramesMeta [1313f7d8] log:\n \xe2\x94\x9c\xe2\x94\x80DataFramesMeta [1313f7d8] has no known versions!\n \xe2\x94\x94\xe2\x94\x80restricted to versions * by an explicit requirement \xe2\x80\x94 no versions left\nRun Code Online (Sandbox Code Playgroud)\nCUDA
\n(@v1.5) pkg> add CUDA\n Resolving package versions...\nERROR: Unsatisfiable requirements detected for package CUDA [052768ef]:\n CUDA [052768ef] log:\n \xe2\x94\x9c\xe2\x94\x80CUDA [052768ef] has no known versions!\n \xe2\x94\x94\xe2\x94\x80restricted to versions * by an explicit …Run Code Online (Sandbox Code Playgroud) 我在 Julia(编辑器 - Atom)中Unsatisfiable requirements导入该包的最新 github 版本时遇到了一些问题Geostats。为了避免包之间的任何冲突,我使用虚拟环境。
(Virtualenv) pkg> add https://github.com/JuliaEarth/GeoStats.jl.git\n Cloning git-repo `https://github.com/JuliaEarth/GeoStats.jl.git`\n Updating git-repo `https://github.com/JuliaEarth/GeoStats.jl.git`\n Updating registry at `C:\\Users\\User\\.julia\\registries\\General`\n Updating registry at `C:\\Users\\User\\.julia\\registries\\JuliaComputingRegistry`\n Resolving package versions...\nERROR: Unsatisfiable requirements detected for package Variography [04a0146e]:\n Variography [04a0146e] log:\n \xe2\x94\x9c\xe2\x94\x80possible versions are: [0.2.0-0.2.2, 0.3.0-0.3.7, 0.4.0-0.4.3, 0.5.0-0.5.10, 0.6.0-0.6.3, 0.7.0, 0.8.0-0.8.4, 0.9.0-0.9.1, 0.10.0-0.10.4, 0.11.0-0.11.1] or uninstalled\n \xe2\x94\x94\xe2\x94\x80restricted to versions 0.12 by GeoStats [dcc97b0b] \xe2\x80\x94 no versions left\n \xe2\x94\x94\xe2\x94\x80GeoStats [dcc97b0b] log:\n \xe2\x94\x9c\xe2\x94\x80possible versions are: 0.23.0 or uninstalled\n \xe2\x94\x94\xe2\x94\x80GeoStats [dcc97b0b] …Run Code Online (Sandbox Code Playgroud) 我想复制 python 函数的功能int(),它可以将string或转换float为int以 10 为基数的类型。
参考: https: //www.w3schools.com/python/ref_func_int.asp
我开发了一个小代码来执行此执行:
a = "5.9"
print("Type of a = ", typeof(a))
if typeof(a) == String
x1 = reinterpret(Int64, a) # 1st attempt
x1 = parse(Int, a) # 2nd attempt
else
x1 = floor(Int64, a)
end
print("\nx1 = $x1", ",\t","type of x1 = ", typeof(x1))
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我展示了将字符串转换为类型的函数int,但两者都不起作用。
请建议一个可以将其转换string为的解决方案int,以及是否有任何建议来优化上述代码?
谢谢!
我想python like list在 Julia中将数组转换为 a 。
要创建一个数组,type Any可以使用此语法初始化一个空数组array = []。但是,如果我想执行转换,即让一个类型的数组Array(Float64,1)来输入Any,那么正确的方法是什么?
或者如果有任何其他方法可以在 Julia 中创建列表?
我创建一个函数的方法,该函数接受一个数组并将其转换为任何类型:
function list(x)
x = convert(Any, x)
return x
end
x_test = [0.19, 0.03, 0.27]
t1 = typeof(x_test)
println("type of x_test is: $t1")
x_test = list(x_test)
t2 = typeof(x_test)
println("type of x_test is: $t2")
Output:
type of x_test is: Array{Float64,1}
type of x_test is: Array{Float64,1}
Run Code Online (Sandbox Code Playgroud)
请提出实现此转换任务的方法或解决方案。
谢谢。