考虑以下代码,我只想更改1个单元格,但整个行都会更改:
df=DataFrames.DataFrame(A=[1,2],B=[3,4])
df[2,:A]=7 # this is OK, changes only 1 cell
df[:,1:end]=0.0 # this line somehow makes the change in the next line behave unexpectedly
df[2,:A]=7 # entire 2nd row is 7
Run Code Online (Sandbox Code Playgroud)
就像df[:,1:end]=0.0
将该行的所有单元格设置为相同的引用一样; 但我将它设置为0.0,所以我希望这是一个值副本,而不是参考副本
版本:julia版本0.4.6-pre DataFrames v"0.7.8"
这里发生了一些别名。我认为这是 中的一个错误DataFrames
,尽管它可能是预期的行为,尽管很奇怪。所发生的情况是两个列都使用相同的基础数据。参见#1052。
作为解决方法,您可以逐一设置列:
for c in 1:size(df, 2)
df[:,c] = 0.0
end
Run Code Online (Sandbox Code Playgroud)