Consider the following code, where I want to change only 1 cell, but the entire row gets changed:
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
It's as if the df[:,1:end]=0.0
sets all the cells of that row to the same reference; but I am setting it to 0.0, so I expect this to be a value copy, not reference copy
Versions: julia version 0.4.6-pre DataFrames v"0.7.8"
Adding extra rows and columns to the data frame New rows can be added to the end of a data frame by using push!() function.
Additionally, in your example, you should use select! in order to modify the column names in place, or alternatively do 'df = select(df, "col1" => "Id", "col2" => "Name")` as select always return a new DataFrame .
There's some aliasing going on here. I think this is a bug in DataFrames
, though it's possible that it's intended behaviour, albeit strange. What's happening is that the same underlying data is being 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With