0

Suppose there are a few variables that all share the same value, and the variable df_train points to that value.

Now if I reassign df_train to some other frame, all the other variables that pointed at the same object as df_train are now pointing at the old value:

mydata = [df_train, df_test]
df_train = pd.concat( ... ) 
# now the mydata is no longer sharing the same value as df_train

Is it possible to reassign a dataframe in-place? something like:

mydata = [df_train, df_test]
df_train.set(pd.concat(...))
# now mydata still shares state with df_train
user4157124
  • 2,809
  • 13
  • 27
  • 42
Aviad Rozenhek
  • 2,259
  • 3
  • 21
  • 42

1 Answers1

0

I've found a solution, albeit a somewhat smelly one, by using the __init__ method:

mydata = [df_train, df_test]
df_other = # ...
df_train.__init__(df_other) 
# now mydata still shares state with df_train
Aviad Rozenhek
  • 2,259
  • 3
  • 21
  • 42