I have a pandas dataframe as below:
header = [np.array(['location','location','location','location2','location2','location2']),
np.array(['S1','S2','S3','S4','S5','S6'])]
df = pd.DataFrame(np.random.randn(5, 6), columns = header )
df
我希望将数据框导出至 Excel 表格,但不需要索引。以下是我的代码,它可以将我的数据框导出至 Excel 表格,但会包括索引。当我使用参数 index=False 时,会出现错误。
# output all the consolidated input to an excel sheet
out_file_name = os.path.join(folder_location, "templates", future_template)
writer = pd.ExcelWriter(out_file_name, engine='xlsxwriter')
# Write each dataframe to a different worksheet.
df.to_excel(writer, sheet_name='Ratings Inputs')
# Close the Pandas Excel writer and output the Excel file.
writer.save()