Hi ,
I tried to create a new data frame with theminor changes from my original dataframe. But whenever i tried to change something in new dataframe, it gets changed in original as well. Can some one help me to solve this . here is the code i tried.
You should make a copy of value bound to df1 variable:
df2 = copy(df1)
df2 = df1 does not copy value. It just adds binding to the df2 name of a value bound to df1 name. This is discussed in Types · The Julia Language and additionally explained in chapter 2 of Julia for Data Analysis (the content should be available for you to view for free in the preview of the book).
A similar question is posted today for a second time so I also have written a post Values’ mutability in Julia | Blog by Bogumił Kamiński related to the issue of mutability (it covers a bit different aspect than = operator but I hope it will help you to understand the whole concept of mutable values better).
This was also astonishing to me. The issue of “binding vs copying” of value by assignment operator = is AFAICT not clearly explained in The Julia Manual. But maybe I missed the place where it is clearly laid out (in this case please let me know ). It is mentioned eg in. bullet 2 of Noteworthy Differences from other Languages · The Julia Language, but I think it is not a general exposition of the topic.
Also, note that if any of the elements of the columns are mutable themselves, and you may be mutate them, then maybe it is best to use deepcopy instead of copy.