delete multiple dataframes at once in python 1

delete multiple dataframes at once in python

>>> lst = [pd.DataFrame(), pd.DataFrame(), pd.DataFrame()]
>>> del lst     # memory is released

Here is what the above code is Doing:
1. Create a list of 3 empty dataframes
2. Delete the list

The list is deleted, but the dataframes are not.

To delete the dataframes, you need to delete each item in the list.

You can do this by using a for loop:

>>> lst = [pd.DataFrame(), pd.DataFrame(), pd.DataFrame()]
>>> for item in lst:
>>> del item
>>> del lst # memory is released

Or you can use the clear() method:

>>> lst = [pd.DataFrame(), pd.DataFrame(), pd.DataFrame()]
>>> lst.clear()
>>> del lst # memory is released

Similar Posts