Home » excel » Creating an excel table in python

Creating an excel table in python

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have exported data to excel using pandas dataframes and my next plan is to use the data I’ve exported with PowerApps. However, in order to do this the data needs to be formatted as an excel table and I was wondering if there’s a way to automate this?

I’ve had a good look around and am struggling to find anything – please bear in mind I am in no way a python pro and am very new to pandas! Here’s a condensed version of what I’ve got so far:

import pandas as pd

list = [['big', 'nested', 'list'],['big', 'nested', 'list'], ['big', 'nested', 'list'],['big', 'nested', 'list'],['big', 'nested', 'list']]
df = pd.DataFrame(data = list, columns = ['X','Y','Z'])
writer = pd.ExcelWriter('file.xlsx', engine='xlsxwriter')
df.to_excel(writer, index = False)
writer.save()

Ideally I’d like to do this in python rather than try and merge what I’ve done with VBA (which would seem like the more obvious choice I’m guessing) as I’ve no experience whatsoever in VBA nor would know how to link the code to signal the other.. However I’m happy to hear all suggestions! Thank you very much in advance

EDIT: What i’m wondering is if there’s a way to turn this:

Current output

into this

Ideal Output

How to&Answers:

Use XLSXWriter’s add table option

worksheet.add_table('from_column:to_column', {'first_column': data, 'last_column': data})

For further reference you can refer the official Documentation HERE