python - dataframe append not visible out of function scope -


according understanding of python, mutable references data can modified within function scope , reflect change outside. behavior below confuses me:

1) consider list:

my_list = [] def checklistappend( list ):     list.append( 1 ) checklistappend( my_list ) print ( my_list ) 

as expected variable my_list = [1]

2) consider following scenario dataframe:

my_df = pd.dataframe(columns=['a']) def checkdfappend ( df ):     df.append( [1] ) checkdfappend( my_df ) print( my_df ) 

in case result of my_df still empty data frame columns 'a' non-intuitive , explaination can come dataframe append method internally assigns new variable behavior not expect.

i using python 2.7.2 pandas 0.13.1 , changing either of not in control.

is there way achieve same objective without making many copies ?

you need assign output df.

df = df.append([1]) 

Comments