''' import pandas as pd import xlsxwriter
def write_excel_files(data: pd.DataFrame, file_prefix: str, sheet_prefix: str, row_limit: int = None): """ :param data: pandas.DataFrame object containing data for writing to Excel files :param file_prefix: string prefix for file names of saved Excel files :param sheet_prefix: string prefix for sheet names in saved Excel files :param row_limit: maximum number of rows for a single sheet, optional :return: None """ if row_limit is None: row_limit = len(data)
# Split data into chunks of row_limit size or less
data_chunks = [data[i:i + row_limit] for i in range(0, len(data), row_limit)]
# Iterate through data chunks and write to Excel files
for i, chunk in enumerate(data_chunks):
filename = f"{file_prefix}_{i}.xlsx"
writer = pd.ExcelWriter(filename, engine='xlsxwriter')
# Split chunk into separate data frames for each unique value of the first column
group_dfs = [df for _, df in chunk.groupby(chunk.columns[0])]
# Write each group data frame to a separate sheet in Excel file
for j, group_df in enumerate(group_dfs):
sheet_name = f"{sheet_prefix}_{j}"
group_df.to_excel(writer, sheet_name, index=False)
writer.save()
df = pd.DataFrame({ 'A': ['a', 'a', 'b', 'b', 'c', 'c', 'c', 'd'], 'B': list(range(8)) }) write_excel_files(df, 'example', 'sheet', 3) '''