1👍
It appears you are reading all the data into a dictionary before writing any of it. There is no obvious reason to do that. Try reading / writing in different sized chunks (1 row at a time, 10, 100 etc.) and see which chunk size provides the memory and speed performance you prefer.
Source:stackexchange.com