Thanks for the suggestion - turns out there are much cleaner ways to do this if you dig into the pandas documentation. I'll submit a smoother version.