5

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

7
  • OK, so your code failed? Or there is some problem? Because it seems nice. Commented Jul 2, 2018 at 8:44
  • The code works fine - i'm wondering if you can create an excel table (e.g using excel formatting) from python Commented Jul 2, 2018 at 8:46
  • hmm, so please be more specific, also check this Commented Jul 2, 2018 at 8:47
  • @jezrael OP probably means Excel tables like support.office.com/en-us/article/… Commented Jul 2, 2018 at 8:47
  • Do you mean an Excel table that is created using Ctrl + t in Excel? Commented Jul 2, 2018 at 8:47

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you - this looks perfect!
@Colleen if it was useful, green-tick the answer
Sure thing - sorry i'm new to posting on the site. This did exactly what I needed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.