I have an excel file with about 500,000 rows and I want to split it to several excel file, each with 50,000 rows.
I want to do it with pandas so it will be the quickest and easiest.
any ideas how to make it?
thank you for your help
I have an excel file with about 500,000 rows and I want to split it to several excel file, each with 50,000 rows.
I want to do it with pandas so it will be the quickest and easiest.
any ideas how to make it?
thank you for your help
Assuming that your Excel file has only one (first) sheet containing data, I'd make use of chunksize
parameter:
import pandas as pd
import numpy as npi=0
for df in pd.read_excel(file_name, chunksize=50000):df.to_excel('/path/to/file_{:02d}.xlsx'.format(i), index=False)i += 1
UPDATE:
chunksize = 50000
df = pd.read_excel(file_name)
for chunk in np.split(df, len(df) // chunksize):chunk.to_excel('/path/to/file_{:02d}.xlsx'.format(i), index=False)