Practical Business Python

Taking care of business, one python script at a time


Wed 08 April 2015

Improving Pandas’s Excel Output

Posted by Chris Moffitt in articles   

Pandas makes it very easy to output a DataFrame to Excel. However, there are limited options for customizing the output and using Excel’s features to make your output as useful as it could be. Fortunately, it is easy to use the excellent XlsxWriter module to customize and enhance the Excel workbooks created by Panda’s to_excel function. This article will describe how to use XlsxWriter and Pandas to make complex, visually appealing and useful Excel workbooks. As an added bonus, the article will briefly discuss the use of the new assign function that has been introduced in pandas 0.16.0.

Read more...



Mon 16 February 2015

Creating PDF Reports with Pandas, Jinja and WeasyPrint

Posted by Chris Moffitt in articles   

Pandas is excellent at manipulating large amounts of data and summarizing it in multiple text and visual representations. Without much effort, pandas supports output to CSV, Excel, HTML, json and more. Where things get more difficult is if you want to combine multiple pieces of data into one document. For example, if you want to put two DataFrames on one Excel sheet, you need to use the Excel libraries to manually construct your output. It is certainly possible but not simple. This article will describe one method to combine multiple pieces of information into an HTML template and convert it to a standalone PDF document using Jinja templates and WeasyPrint.

Read more...


Mon 02 February 2015

Generating Excel Reports from a Pandas Pivot Table

Posted by Chris Moffitt in articles   

The previous pivot table article described how to use the pandas pivot_table function to combine and present data in an easy to view manner. This concept is probably familiar to anyone that has used pivot tables in Excel. However, pandas has the capability to easily take a cross section of the data and manipulate it. This cross section capability makes a pandas pivot table really useful for generating custom reports. This article will give a short example of how to manipulate the data in a pivot table to create a custom Excel report with a subset of pivot table data.

Read more...