Purpose: write a function to delete all data frames that start with a specific prefix from the name space.
def del_dfs(prefix):
df_list = [] # I know this list building stage may not be necessary but I need a list of included dfs for other purposes
df_list.append([df for name, df in globals().items() if name.startswith(prefix) and isinstance(df, (pd.Series, pd.DataFrame))])
for df in df_list:
del df
Issue: This simply does not delete the dfs from the namespace. I guess it is related to the deletion happening inside the function but I can not figure out a solution.
update My overall purpose is to find all dfs in the namespace that start with a prefix, concatenate them (I already have a function for this), and then delete the individual dfs from the namespace to free up RAM as I now have them all in a concatenated df.