Python Forum
Exporting data frame to excel - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Exporting data frame to excel (/thread-35158.html)



Exporting data frame to excel - dyerlee91 - Oct-05-2021

Hey everyone. I've got several lists I want to export to excel, but the only thing my script yields is an empty file with no file type. Can anyone point out what element(s) I'm missing to get my lists correctly exported?


data = pd.DataFrame(
    
{'A': [rampdata],
'B' : [vacdropdata],
'C' : [vacdropdata],
'D' : [leakcheckdata],
'E' : [leakcheckdata],
'F' : [runtime4],
'G' : [runtime9],
'H' : [runtime11]}
)

excel_file = C:\Users\212601562\Documents\output"
sheet_name = "Data set"
writer = pd.ExcelWriter(excel_file, engine="xlsxwriter")
data.to_excel(writer, sheet_name=sheet_name)

workbook = writer.book
worksheet = writer.sheets[sheet_name]

chart = workbook.add_chart({'type': 'scatter'})

max_rows = len(data)
col_x = data.columns.get_loc('A') + 1
col_y = data.columns.get_loc('B') + 1

chart.add_series(
    {
     'name' : "Samples",
     'categories' : [sheet_name, 1, col_x, max_rows, col_x],
     'values' : [sheet_name, 1, col_y, max_rows, col_y],
     'marker' : {'type' : 'circle', 'size' : 4},
     'trendline' : {'type' : 'linear'},
     }
    )
chart.set_x_axis({'name' : 'Concentration'})
chart.set_y_axis({'name': 'Measured', 'major_gridlines':{'visible' : False}})

worksheet.insert_chart('D2', chart)
writer.save()