I don’t know python to be able to tell you what the bottleneck is, but what I suggest you do is to create some test data with 100000 account numbers, and see how long each line or section takes to execute. Tweak or replace those areas that take the longest.