I was wondering what are the best resources to learn the best practice when it comes to memory management. For example, lets say I have the following code below:
df.read_csv() #one instance of a df df1 = df.drop_duplicates #another instance of a df, total 2 df1_melt = df1.melt() #another instance of a df df1_aggregated = df1_melt.groupby()... #another instance, total 4 df_mutual = pd.merge(df1_aggregated, df1_melted) #created another instance of a df, total 5
In the example above, we created 5 dataframes and stored them in memory, but we're really only interested in one. I have read that you can reduce the reference count to these variables to 0, and then when you delete the variable, it may be garbage collected. Is there a better way to program in a manner that I avoid creating multiple copies of the data in memory?