Julia DataFrame,参数:保留在`dataFramerow'的广播上
如果我想将矢量添加到数据框的每一列,我可以广播它。相反,如果我在同一数据框架的所有行上循环,然后要广播到所有列,我会得到错误
参数:保留``dataframerow''的广播
这将是一个最小的(非)工作示例:
d = DataFrame()
#create the list with column names
columnlist = [:a, :b, :c, :d]
#each column is filled with [0, 0, ...] of length 10
for col in columnlist
d[!, col] = zeros(10)
end
#then I want to add a "1" to each entry
#this does work
d[!, columnlist] .+= ones(10)
#this does produce the error mentioned above
for row in 1:nrow(d)
dfrow = d[row, :]
dfrow[columnlist] .+= ones(4) #ArgumentError: broadcasting over `DataFrameRow`s is reserved
end
#this also does not work, with the same error
for row in 1:nrow(d)
d[row, columnlist] .+= ones(4) #ArgumentError: broadcasting over `DataFrameRow`s is reserved
end
是预期的行为还是错误?还是我监督愚蠢的东西?是否有一种方法可以广播到DataFramerow的所有列? (我知道朱莉娅(Julia)是列的事实,但是由于我需要进行一些重型插值,包括每行一次I/O一次,因此这种方式更快了)
我正在使用Julia 1.7.2和DataFrames v1.3.4在Ubuntu 20.04.4上。
If I want to add a Vector to each column of a Dataframe, I can broadcast it. If instead I loop over all rows of the same DataFrame and then want to broadcast to all columns, I get the error
ArgumentError: broadcasting over `DataFrameRow`s is reserved
This would be a minimal (non-) working example:
d = DataFrame()
#create the list with column names
columnlist = [:a, :b, :c, :d]
#each column is filled with [0, 0, ...] of length 10
for col in columnlist
d[!, col] = zeros(10)
end
#then I want to add a "1" to each entry
#this does work
d[!, columnlist] .+= ones(10)
#this does produce the error mentioned above
for row in 1:nrow(d)
dfrow = d[row, :]
dfrow[columnlist] .+= ones(4) #ArgumentError: broadcasting over `DataFrameRow`s is reserved
end
#this also does not work, with the same error
for row in 1:nrow(d)
d[row, columnlist] .+= ones(4) #ArgumentError: broadcasting over `DataFrameRow`s is reserved
end
Is that the expected behaviour, or a bug? Or am I overseeing something stupid? And is there a way how to broadcast to all columns of a DataFrameRow? (I am aware of the fact that Julia is column-major, but as I need to do some heavy interpolation including I/O once for each row, it is faster this way)
I am using Julia 1.7.2 and DataFrames v1.3.4 on Ubuntu 20.04.4.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是预期的。原因是朱莉娅(Julia)尚未决定如何处理
名为tuple
>>:如果您想使用广播的方式来执行此操作(直到基础朱莉娅(Base Julia)决定如何处理
nater nationtuple s)是:
或只是不使用广播,而是其他一些获得相同结果的方法:
注意:这是您问题的答案。我没有专注于使您的代码最有效。如果您有绩效问题,您可以问另一个问题,确切地指定您的问题是什么,我会尝试提供帮助。
This is expected. The reason is that Base Julia has not decided yet how to handle broacasting of
NamedTuple
:If you want to use broadcasting the way to do it (till Base Julia decides what to do with
NamedTuple
s) is:or just do not use broadcasting but some other method to get the same result:
Note: this is an answer to your question. I have not focused on making your code most efficient possible. If you have a performance issue can you please ask another question specifying exactly what is your problem and I will try to help.