Python-bloggers

How to list the worksheet names of an Excel workbook using Python Pandas

This article was first published on Stringfest Analytics , and kindly contributed to python-bloggers. (You can report issue about the content on this page here)
Want to share your content on python-bloggers? click here.

I’ve mentioned a few times on this blog (example) about the growing possibility for Python <> Excel interoperability. Here’s a simple task done in a way I wasn’t aware of (h/t — where else? — StackOverflow.)

Usually when combining Python and Excel I use specific packages like openpyxl, xlwings or xlsxwriter for a very rich suite of tools. It would be hard to find any Excel task that couldn’t be automated from these packages.

It would also be hard to get much data analysis done with pandas, which does have some limited features for working with Excel. And apparently one of them is getting a list of worksheet names. This is all I really wanted to do and I had pandas open anyway, so why not do it this way?

Introducing ExcelFile()

Usually my first move when working with an Excel file from pandas is to read it in with read_excel(). However, another option is ExcelFile. Follow along with the below Jupyter notebook to see how it’s done:

I hope you can find ExcelFile() when working with Python and Excel in a pinch.

How have you used these programs together? Do you have any questions about doing so? Let me know in the comments.

To leave a comment for the author, please follow the link and comment on their blog: Stringfest Analytics .

Want to share your content on python-bloggers? click here.
Exit mobile version