Pandas - Slice Large Dataframe in Chunks
You can use list comprehension to split your dataframe into smaller dataframes contained in a list.
n = 200000 #chunk row size
list_df = [df[i:i+n] for i in range(0,df.shape[0],n)]
You can access the chunks with:
list_df[0]
list_df[1]
etc...
Then you can assemble it back into a one dataframe using pd.concat.
By AcctName
list_df = []
for n,g in df.groupby('AcctName'):
list_df.append(g)
I'd suggest using a dependency more_itertools
. It handles all edge cases like uneven partition of the dataframe and returns an iterator that will make things a tiny bit more efficient.
from more_itertools import chunked
CHUNK_SIZE = 5
index_chunks = chunked(df.index, CHUNK_SIZE)
for ii in index_chunks:
df.iloc[ii] # your dataframe chunk ready for use