[Tutor] Interoperating with Excel, was Re: Questions

Peter Otten __peter__ at web.de
Sun Apr 7 08:07:24 EDT 2019


Diana Katz wrote:

> 1) Can you use python from excel? Or just export to excel?
> 2) I am trying to see if there's a way using python to automate all of
> this work that I need to do. I have to collect quarterly segment data for
> hundreds of public companies and go back at least 12-16 quarters. We use
> an aggregator like factset and they actually don't have this option
> available in an automated way. So I'm trying to see if there's a way to
> build this. Basically, I get my data from sec.gov and they have
> interactive data - they even have the data in excel (though it's a messy
> file and hard to read). I attached some of the steps and the data that i'd
> want to see. Basically i'd want the excel to look like:
> old to new quarters - going back 12 to 16 quarters (more if possible but
> not if it will stop the project).
>  Columns: 3/31/2017, 6/30/2017, 9/30/17, 12/31/17, 3/313/2018...
> Rows:
> Sales for segment A
> Sales for Segment b
> Sales for SEgment C
> …(for as many segments as they have)
> 
> Earnings for Segment A
> .Earnings for Segment B
> 
> Depreciation for Segment A
> Depreciation for Segment B
> Depreciation for Segment C...

These look like "pivot tables" which are well supported by Excel.
I expect that this is easy to automate with a little bit of Basic.

Of course you can build these tables with a Python script if you feel more 
comfortable in Python. Then either write them into csv files ("comma 
separated value", supported by the standard library) 

https://docs.python.org/3/library/csv.html

which can be read by Excel -- or use a dedicated library. Google came up 
with

https://xlsxwriter.readthedocs.io/

> I included where I get the data in the attached document.

Attachments don't make it to the list. You have to provide a link or (if 
they're small and text-only) paste your data and scripts into the message 
body.




More information about the Tutor mailing list