This extends Paul's answer. In Pandas, indexing a DataFrame returns a reference to the original DataFrame. Thus, changing the subset will change the original DataFrame. So you want to use a copy if you want to make sure that the original DataFrame should not be changed. Consider the following code:
df = DataFrame({'x': [1,2]}) df_sub = df[0:1] df_sub.x = -1 print(df)
You'll get:
x 0 -1 1 2
In contrast, the following df leaves do not change:
df_sub_copy = df[0:1].copy() df_sub_copy.x = -1
cgold Dec 28 '14 at 8:01 2014-12-28 20:01
source share