1

i want copy DataFrame to another

there is 2 method to copy DataFrame to another which method is good and sad

label=train.copy()

label=train
juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
GursimranSe
  • 99
  • 2
  • 8
  • 3
    `copy()` gives you a copy with different memory allocation. `label = train` only gives you an alias, that is, same memory, and if you change `label`, say `label.iloc[0] = 0`, you change `train` as well. – Quang Hoang May 31 '19 at 17:59
  • 1
    Yes. The first copy data to a new memory location. The second just creates a new pointer to the same object in its current memory. – Scott Boston May 31 '19 at 18:01
  • 3
    Possible duplicate of [What exactly is the difference between shallow copy, deepcopy and normal assignment operation?](https://stackoverflow.com/questions/17246693/what-exactly-is-the-difference-between-shallow-copy-deepcopy-and-normal-assignm) – juanpa.arrivillaga May 31 '19 at 18:33
  • 1
    Note: it is better to think of python names as acting as keys in various symbol tables, 'namespaces', which are often implemented as literal `dict` objects, and assignment as moving various pointers around various symbol tables. – juanpa.arrivillaga May 31 '19 at 18:36
  • TL:DR `label=train` does *not* copy at all, whereas `.copy` does. – juanpa.arrivillaga May 31 '19 at 18:37

0 Answers0