default_formats(){'params': '{:.2f}',
'tstats': '{:.2f}',
'pvalues': '{:.3f}',
'se': '{:.2f}',
'r2': '{:.3f}',
'nobs': '{:.0f}'}
rgetattr (obj, attr, *args)
Recursive getattr (for nested attributes).
rsetattr (obj, attr, val)
Recursive setattr (for nested attributes).
default_formats ()
Default output formats for some very common statistics.
{'params': '{:.2f}',
'tstats': '{:.2f}',
'pvalues': '{:.3f}',
'se': '{:.2f}',
'r2': '{:.3f}',
'nobs': '{:.0f}'}
get_stars (pvalues:pandas.core.series.Series, stars:dict={0.1: '*', 0.05: '**', 0.01: '***'})
For each pvalue, check the lowest key in stars for which the pvalue is smaller than that key, and return the corresponding nr of stars.
| Type | Default | Details | |
|---|---|---|---|
| pvalues | Series | This is compared to key of stars param to determine how many stars should be added |
|
| stars | dict | {0.1: ‘’, 0.05: ’’, 0.01: ’’} | Todo: default values to the left are star symbols that are not rendered correctly in markdown |
| Returns | Series |
x1
x2 **
x3 ***
dtype: object
x1 ***
x2 **
x3 **
dtype: object
model_groups (column_group_names:Dict[str,List[int]], add_clines:bool=True)
Returns LaTex code needed to add at the top of the table in order to give names to groups of columns in the table.
| Type | Default | Details | |
|---|---|---|---|
| column_group_names | Dict | Keys are group titles, values are lists of column indices included in each group | |
| add_clines | bool | True | If True, adds lines below group names |
| Returns | str |
& \multicolumn{2}{c}{Group 1} & \multicolumn{2}{c}{Group 2} \\
\cline{1-2} \cline{3-4}
tex_table_env (nr_columns:int, env:Literal['tabularx','tabular*']='tabular*')
Creates LaTex code to add at the top of the table to create the correct tabular environment.
| Type | Default | Details | |
|---|---|---|---|
| nr_columns | int | Number of columns in the table | |
| env | Literal | tabular* | Latex tabular environment specification |
| Returns | Tuple |
\begin{tabularx}{\textwidth}{@{}l *{4}{>{\centering\arraybackslash}X}@{}}
\end{tabularx}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l*{4}{c}}
\end{tabular*}
df_to_tex (df:pandas.core.frame.DataFrame, panel_title:str='', palign:Literal['l','r','c']='l', col_groups:Dict[str,List[int]]=None, col_names:Union[List[str],bool]=True, hlines:List[int]=[], tabular_env:str='tabular*')
Creates LaTeX-formatted table from DataFrame.
| Type | Default | Details | |
|---|---|---|---|
| df | DataFrame | If this has a MultiIndex, only the first level is kept | |
| panel_title | str | ||
| palign | Literal | l | Alignment of panel title |
| col_groups | Dict | None | Keys are group names; values are lists of consecutive indices of columns in the group |
| col_names | Union | True | If False, none; if True, use df column names; if list, gives custom column names |
| hlines | List | [] | Row indices under which to place hline (use 0 for topline). adds under each line |
| tabular_env | str | tabular* | LaTex tabular environment |
| Returns | str |
Panel title (if any) will appear first, then column group names(if any), then column names (if any), then the body of the table.
| A | B | C | D | |
|---|---|---|---|---|
| Var1 | 0.153388 | 0.740063 | 0.318769 | 0.741419 |
| 0.981220 | 0.349820 | 0.750357 | 0.868395 | |
| Var2 | 0.987855 | 0.133089 | 0.928428 | 0.600271 |
| 0.120149 | 0.177721 | 0.108870 | 0.844516 | |
| R2 | 0.696665 | 0.187199 | 0.966317 | 0.972379 |
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l*{4}{c}}
\hline \noalign{\smallskip}
\multicolumn{5}{@{} l}{Dependent variable is Y} \\
& \multicolumn{2}{c}{Group 1} & \multicolumn{2}{c}{Group 2} \\
\hline \noalign{\smallskip}
\cline{2-3} \cline{4-5}
& A & B & C & D \\
Var1 & 0.15338774256333254 & 0.7400625640619886 & 0.31876894791132926 & 0.741418501204769 \\
& 0.981219771218718 & 0.34981974576456365 & 0.7503573114766038 & 0.8683948957807631 \\
Var2 & 0.9878546825283399 & 0.1330892261743063 & 0.9284283603986899 & 0.6002709049430831 \\
\hline \noalign{\smallskip}
& 0.12014853367450873 & 0.17772097286209887 & 0.10887029741896503 & 0.8445164146587155 \\
R2 & 0.6966651718648458 & 0.18719853238388184 & 0.9663168811371031 & 0.9723793915445124 \\
\end{tabular*}
make_pdf_from_tex (tex_file_path:pathlib.Path|str)
Output PDF is created in the same folder as source tex file. Requires TexLive and its pdflatex utility
open_pdf_file (file_path)