I'm doing some data analysis, and the data are in pandas
# do some process work on df
df = df_process(df)
Far better would be:
def df_process(df): # do some process work on df def df_another(df): # other processing def df_more(df): # yet more processing def process_many(df): for frame_function in (df_process, df_another, df_more): df_copy = df.copy() frame_function(df_copy) # emit the results to a file or screen or whatever
The key here is if you must make a copy, make only one, process it, stash the results somewhere and then dispose of it by reassigning
df_copy. Your question made no mention of why you are hanging onto processed copies so this assumes you need not.