Julia dataframe changing one cell changes the whole row

Consider the following code, where I want to change only 1 cell, but the whole row changes:

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 

As if df[:,1:end]=0.0 sets all the cells of this row to the same link; but I set it to 0.0, so I expect it to be a copy of the value, not a copy of the link

Version: julia version 0.4.6-pre DataFrames v "0.7.8"

+6
source share
1 answer

There is some overlap. I think this is a mistake in DataFrames , although it is possible that this suggested behavior, albeit strange. What happens is that the same underlying data is used by both columns. See # 1052 .

As a workaround, you can set the columns one by one:

 for c in 1:size(df, 2) df[:,c] = 0.0 end 
+4
source

All Articles