考虑以下代码,我只想更改 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
就好像
df[:,1:end]=0.0
将该行的所有单元格设置为相同的引用;但我将它设置为 0.0,所以我希望这是一个值副本,而不是引用副本版本:
Julia 版本 0.4.6-pre
数据帧 v"0.7.8"
最佳答案
这里发生了一些混叠。我认为这是 DataFrames
中的一个错误,尽管它可能是有意的行为,尽管很奇怪。发生的情况是两列都使用相同的基础数据。见 #1052 .
作为一种解决方法,您可以一一设置列:
for c in 1:size(df, 2)
df[:,c] = 0.0
end
关于dataframe - julia 数据框更改一个单元格会更改整行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39320783/