I have two large NumPy arrays each with shape of (519990,) that look something like this:
Order = array([0, 0, 0, 5, 6, 10, 14, 14, 14, 23, 23, 39])
Letters = array([A, B, C, D, E, F, G, H, I, J, K, L])
As you can see the first array is always in ascending and a positive number. I would like to group everything within the Letters to Order to turn out looking like this:
{0:[A,B,C], 5:[D], 6:[E], 10:[F], 14:[G, H, I], 23:[J, K], 39:[L]}
The code I have to do this is:
df = pd.DataFrame()
df['order'] = Order
df['letters'] = Letters
linearDict = df.grouby('order').apply(lambda dfg:dfg.drop('order', axis=1).to_dict(orient='list')).to_dict()
endProduct = {}
for k, v in linearDict.items():
endProduct[k] = np.array(linearDict[k]['letter'][0:])
enProduct = {0:array([A,B,C]), 5:array([D]), 6:array([E]), 10:array([F]), 14:array([G, H, I]), 23:array([J, K]), 39:array([L])}
My problem is this process is BEYOND slow. It's such a drain on the system that it causes my Jupyter Notebook to crash. Is there a faster way of doing this?