Created
July 23, 2024 14:05
-
-
Save cyb3rsalih/d9c06486fa75f0836b8ac70123fd688f to your computer and use it in GitHub Desktop.
Revisions
-
cyb3rsalih created this gist
Jul 23, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import pandas as pd # Function to split the DataFrame into smaller DataFrames def split_dataframe(df, chunk_size): return [df[i : i + chunk_size] for i in range(0, df.shape[0], chunk_size)] # Read the Excel file input_file = "input.xlsx" df = pd.read_excel(input_file) # Define the number of records per split file records_per_file = 1000 # Adjust as needed # Split the DataFrame chunks = split_dataframe(df, records_per_file) # Save each chunk to a new Excel file for i, chunk in enumerate(chunks): output_file = f"output_{i+1}.xlsx" chunk.to_excel(output_file, index=False) print(f"Saved {output_file}") # /w ChatGPT