@save_and_reload_df
def my_func():
# Create and fill the dataframe
df = pd.DataFrame(...)
df = ...
return df
What the decorator does:
On the first execution of the function, it will retrieve the returned dataframe and save it at data/my_func.csv.
When the function is called again, if the file data/my_func.csv exists, it will not call my_func() but just read the file and return the dataframe.
If one wants to compute the dataframe again, just call my_func(overwrite=True) (argument added automatically by the decorator), the decorator will call the function, save and return the new dataframe.
Add save_and_reload_df decorator and minor modifs
Usage:
What the decorator does: On the first execution of the function, it will retrieve the returned dataframe and save it at
data/my_func.csv
. When the function is called again, if the filedata/my_func.csv
exists, it will not callmy_func()
but just read the file and return the dataframe. If one wants to compute the dataframe again, just callmy_func(overwrite=True)
(argument added automatically by the decorator), the decorator will call the function, save and return the new dataframe.