StatsReporting / stargazer

Python implementation of the R stargazer multiple regression model creation tool
Other
197 stars 48 forks source link

Adding ASCII and Markdown output rendering #10

Open cproctor opened 5 years ago

cproctor commented 5 years ago

Hi! This is my first ever pull request, so please let me know if I've missed some crucial etiquette. I needed regression tables for my Python/markdown-based dissertation build system, and adding it to stargazer seemed like the shortest path. Maybe someone else will benefit too! Here's a rundown of the proposed changes:

I implemented an abstract set of generate_cells methods, following the code paths from the generate_html methods. These return a two-dimensional array of strings, which could be used for other render formats as well. (It might be valuable to refactor the html output to use this where possible.) The 2d grid of cells intentionally limits some of the functionality--no rowspans or colspans are supported.

I also added a few new properties which will be valuable for anyone trying to export markdown regression tables:

The separators could be changed to \n, which is particularly nice because tabulate converts newlines into whatever markdown format is requested. The sig_char may need to be replaced by an escaped version of itself in some output contexts.

Once the generate_cells methods were implemented, I use tabulate (new dependency) to render these cells to ascii or any supported flavor of markdown.

toobaz commented 4 years ago

Hi @cproctor , thank you very much for your contribution.

I'm afraid right now the stargazer code needs deeper changes (#46 ) in order to support further formats in the best way, but once we settle on the general structure it would be great if you could rebase your code: the proposed feature is definitely interesting.