1

Title says it. In the accepted answer to StackOverflow 34884536 it says

You can find a longer discussion of the nature of the problem here, but the main take-away is that we're now moving to a "copy-on-write" behavior in which any time you slice, you get a new copy, and you never have to think about views.

...

Best guess is the fix will be in within a year -- in the mean time, I'm afraid some .copy() may be necessary, sorry!

(answered 2016/01/20)

Does df.loc[] return a 'copy' now? Or to be safe do I still have to use .copy()?

brunston
  • 1,244
  • 1
  • 10
  • 18

2 Answers2

1

It returns a copy. You can test this by making a copy, assigning an index via .loc to another variable, changing the variable, and noticing that the original frame doesn't change.

Slightly related, but further info here: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

Landmaster
  • 1,043
  • 2
  • 13
  • 21
0

It may return a copy or a view depending on the underlying structure of the dataframe. To be safe you should use .copy()

A good example of the difference in behavior is given there: In Pandas, does .iloc method give a copy or view?

guiweb
  • 965
  • 6
  • 12