Issue
I'm not going to share the direct code since I feel the length of it would bog down anyone's analysis of my main question (though I can share it if absolutely need be). It's best I summarize it.
To put it generally, in a previous cell, I established a pandas dataframe - let's say we call it original_df here. In the next cell, I initialize a new variable temp_df = original_df so that I may manipulate the same data while keeping the original dataframe in tact. At no point in the code that follows do I ever once assign anything to nor even use original_df in any way, yet when I get done manipulating temp_df as much as I need to...subsequently checking original_df shows that it has changed in all the same ways that temp_df did.
Any ideas why this would happen?, some type of environment issue perhaps? Re-running each of the code cells that created original_df is rather inconvenient, and putting all of the code in one cell would negate the whole point of using a Jupyter Notebook (given the visuals along the way). I find it incredibly bizarre that this is happening at all, but is there any way to explicitly force a "freeze" on the original_df variable while its temp_df copy is being manipulated?
Solution
You could try to copy the dataframe with the libary copy
import copy
temp_df = copy.copy(original_df)
Answered By - clanky1997
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.