How would you refactor a long-running Pandas script that is currently running out of memory on large datasets?