-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to render as an excel file/pandas table #77
Comments
I suspect preparing all numerical values (coefficients, stats...) in a Pandas table, and possibly saving it to Excel, would not be difficult (although it probably requires a different code flow compared to the currently supported formats). What seems to me significantly more difficult is formatting the table so that it actually looks nice inside a document, including the borders, but also the alignment, numbers formatting (e.g. number of digits)... this can't be done through Pandas, requires good (better than mine, at least) knowledge of xlwt or similar, and presumably needs a rewrite for each format (xls vs. xlsx vs. ods). So all this said, even if I found the time to implement the first part, I think the best approach to including a table in a Word document would still be either to copy from a browser (e.g. jupyter notebook) the html generated by stargazer, or to directly include a pdf generated by stargazer. In any case, it might be that I'm too pessimistic and I'm ready to accept contributions. |
@NicolasWoloszko and @toobaz, I took the liberty to start working on an excel renderer. Let me know if something like the below is what you are looking for! Currently I am working with the example data from the test file: import pandas as pd
import statsmodels.formula.api as smf
from stargazer.stargazer import Stargazer
df = pd.DataFrame(list(zip(range(9), range(0, 18, 2))), columns =['a', 'b'])
est1 = smf.ols('a ~ 0 + b', df).fit()
est2 = smf.ols('a ~ 1 + b', df).fit()
stargazer = Stargazer([est1, est2]) Calling the excel renderer works similar to the html and LaTeX renderers: stargazer.render_excel(filename='test.xlsx') Which returns the following table in the |
Cool! Is it based on openpyxl? I can take a look at the code when you want, but consider splitting the code to a separate file if you like - we can even move the html and LaTeX renderers to separate files for consistency. |
Is render_excel already merged with the main? The code does not seem to be working for me. |
Thanks. No, I actually use the
The example I showed you is generated by a prototype. I will work on it a bit more and share the code here for feedback.
I'll take a look at the structure of the package and whether branching out to separate files would work. |
Hi @achinmay17, thanks for your interest in the excel renderer. Currently it is still a work in progress and therefore not merged with the main. But given the positive feedback I will put some extra effort in to get it finished! |
I have no strong preference. |
@toobaz I have created a PR for you to check. For now I have kept all renderers in the same file but we can definitely split them into separate files if you'd like to so. |
Excel file remains the easier format for a table to be inserted in a word document...
Or a pandas table ?
The text was updated successfully, but these errors were encountered: