import pandas as pd
bigdata = [{"a":10,"b":20},
{"a":10,"b":20},
{"a":10,"b":20},
{"a":10,"b":20},
{"a":10,"b":20},
{"a":10,"b":20},
{"a":10,"b":20},
{"a":10,"b":20},
{"a":10,"b":20},
{"a":10,"b":20},
{"a":10,"b":20},
{"a":10,"b":20},
]
# Create a Pandas DataFrame with your data
df = pd.DataFrame(bigdata)
# Split the DataFrame into chunks that fit within the sheet size limit
chunk_size = 2 # Change this to a size that fits your data and system
chunks = [df.iloc[i:i + chunk_size] for i in range(0, df.shape[0], chunk_size)]
# Create a new Excel file
with pd.ExcelWriter('./output.xlsx') as writer:
# Write each chunk to a new sheet in the Excel file
for i, chunk in enumerate(chunks):
sheet_name = f'sheet_{i}'
chunk.to_excel(writer, sheet_name=sheet_name, index=False)
pandas拆分数据写入不同sheet
最新推荐文章于 2024-07-22 15:15:29 发布