adding to multiindexed pandas dataframe by specific indices is incredibly slow

Viewed 14

I have a rather large data frame (~400M rows). For each row, I calculate which elements in another data frame (~200M rows) I need to increment by 1. This second data frame is indexed by three parameters. So the line I use to do this looks like:

total_counts[i].loc[zipcode,j,g_durs[j][0]:g_durs[j][-1]+1] += 1

The above line works, but it appears to be a horrendous bottleneck and takes almost 1 second to run. Unfortunately, I cannot wait 11 years for this to finish.

Any insights on how I might speed up this operation? Do I need to split up the 200M row data frame into an array of smaller objects? I don't understand exactly what is making this so slow.

Thanks in advance.

0 Answers
Related