[英]Writing xls from python row wise using pandas
I have sucessfully created.xlsx files using pandas我已经使用 pandas 成功创建了.xlsx 文件
df = pd.DataFrame([list of array])
df = pd.DataFrame([数组列表])
'''
: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
But I have issue here, There is unnecessary SNo.但我在这里有问题,有不必要的 SNo。 which i dont want, how to do I remove that.
我不想要,我该怎么做才能删除它。
There is SNo.有 SNo。 as first row and column, How do i remove that?
作为第一行和第一列,我如何删除它?
You can take reference from this https://medium.com/better-programming/using-python-pandas-with-excel-d5082102ca27 post of medium for this.您可以参考这篇https://medium.com/better-programming/using-python-pandas-with-excel-d5082102ca27中的帖子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.