TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial…

Member-only story

Automation with PyWin32

Automate Pivot Table with Python (Create, Filter and Extract)

Automate Pivot Table and extract data from the filtered Pivot Table. Save your time for a cup of tea.

KahEm Chu
TDS Archive
Published in
11 min readMay 22, 2021

--

Photo by Jasmine Huang on Unsplash

In Automate Excel with Python, the concepts of the Excel Object Model which contain Objects, Properties, Methods and Events are shared. The tricks to access the Objects, Properties, and Methods in Excel with Python pywin32 library are also explained with examples.

Now, let us leverage the automation of Excel report with Pivot Table, one of the most wonderful functions in Excel!

Why PyWin32?

You may curious why don’t we use pandas.DataFrame.pivot or pandas.DataFrame.pivot_table from pandas library instead? It’s a built-in library that we don’t even need to install.

Well, the two pandas functions mentioned above can create the Pivot Table easily, but if you are preparing an Excel report which will be accessed by other domain users, the hard-coded pivot table created may not favour them as they cannot modify the Pivot Table Fields.

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

KahEm Chu
KahEm Chu

Written by KahEm Chu

Date Science and Analytics Graduate. Passionate in data science, decision science and automating stuff =]

Responses (16)