这是一种方法:
import pandas as pd
Numpy_Array1 = [10, 20, 30, 20, 15]
Numpy_Array2 = [10, 20, 30, 20, 15, 30, 45]
df1 = pd.DataFrame(Numpy_Array1)
df2 = pd.DataFrame(Numpy_Array2)
writer = pd.ExcelWriter('Results.xlsx', engine='xlsxwriter')
df1.to_excel(writer, sheet_name = 'Array1')
df2.to_excel(writer, sheet_name = 'Array2')
workbook = writer.book
worksheet = writer.sheets['Array1']
last_row = len(Numpy_Array1) + 2 # Allow for header row and padding.
col = 0
worksheet.write(last_row + 0, col, 'a')
worksheet.write(last_row + 1, col, 'b')
worksheet.write(last_row + 2, col, 'c')
worksheet.write(last_row + 3, col, 'd')
col = 1
worksheet.write(last_row + 0, col, 10)
worksheet.write(last_row + 1, col, 20)
worksheet.write(last_row + 2, col, 40)
worksheet.write(last_row + 3, col, 80)
# Repeat for Numpy_Array2 or add a loop.
writer.save()
输出:
解决方案的关键是获取底层工作簿的句柄并从那里获取工作表。有关更多信息,请参阅XlsxWriter 文档的使用 Pandas 章节。