How to change global dataframes with function?
I’d like to write a function which adds columns to a global dataframe df1, which is predefined. So, I called global in the function and defined df1 as another dataframe. But when I call df1 in console, it still remains how it was before I call the function.
My codes are like this:
df1 = [] # a (24, 13) size dataframe def inte(): global df1 a = df2 # another dataframe with same indexes df1 = pd.merge(df1, a, left_index=True, right_index=True) return df1
Here the result is an (24, 14) dataframe, which is manipulated as I’d like to.
[24 rows x 14 columns] Empty DataFrame Columns: [gaze, playtime, talkspeed, talktime, volume_ave, volume_max, volume_min, keyword, negativeword, badscenario, leftmove, rightmove, cluster, 0] Index: []
But when I call df1 again in the console:
[24 rows x 13 columns]
Is shown and nothing is changed.
What have I messed up? Any advice would be really appreciated.