我已经成功地创建了.xlsx文件使用熊猫
df = pd.DataFrame([list of array])
'''
:param data: Data Rows
:param filename: name of the file
:return:
'''
df = pd.DataFrame(data)
# my "Excel" file, which is an in-memory output file (buffer)
# for the new workbook
excel_file = BytesIO()
writer = pd.ExcelWriter(excel_file, engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1_test')
writer.save()
writer.close()
# important step, rewind the buffer or when it is read() you'll get nothing
# but an error message when you try to open your zero length file in Excel
excel_file.seek(0)
# set the mime type so that the browser knows what to do with the file
response = HttpResponse(excel_file.read(),
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
# set the file name in the Content-Disposition header
response['Content-Disposition'] = 'attachment; filename=' + filename + '.xlsx'
return response
但我有个问题, 没有不必要的SNo。我不想要,我该怎么去掉它。你知道吗
这是SNo。作为第一行和第一列,如何删除它?你知道吗
你可以从媒体的这个https://medium.com/better-programming/using-python-pandas-with-excel-d5082102ca27帖子中引用。你知道吗
根据文档here
要将索引设置为新列, 将索引用作False
相关问题 更多 >
编程相关推荐