Python Forum
Exporting data frame to excel
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exporting data frame to excel
#1
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()
Larz60+ write Oct-04-2021, 08:13 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Please use bbcode tags on you posts. This was mentioned in moderator note of your first post.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Grouping in pandas/multi-index data frame Aleqsie 3 1,335 Jan-06-2024, 03:55 PM
Last Post: deanhystad
  Filtering Data Frame, with another value NewBiee 9 2,194 Aug-21-2023, 10:53 AM
Last Post: NewBiee
  Data Sorting and filtering(From an Excel File) PY_ALM 0 1,337 Jan-09-2023, 08:14 PM
Last Post: PY_ALM
  Help with poorly formatted excel data armitron121 1 2,004 Jan-13-2022, 07:31 AM
Last Post: paul18fr
  Pandas Data frame column condition check based on length of the value aditi06 1 3,167 Jul-28-2021, 11:08 AM
Last Post: jefsummers
  Adding a new column to a Panda Data Frame rsherry8 2 2,472 Jun-06-2021, 06:49 PM
Last Post: jefsummers
  [Pandas] Write data to Excel with dot decimals manonB 1 6,791 May-05-2021, 05:28 PM
Last Post: ibreeden
  grouped data frame glitter 0 1,835 Feb-02-2021, 11:22 AM
Last Post: glitter
  how to filter data frame dynamically with the columns psahay 0 2,681 Aug-24-2020, 01:10 PM
Last Post: psahay
  Dropping Rows From A Data Frame Based On A Variable JoeDainton123 1 2,561 Aug-03-2020, 02:05 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020