Skip to content

Instantly share code, notes, and snippets.

@Mlawrence95
Last active November 5, 2019 23:17
Show Gist options
  • Save Mlawrence95/4a88f29aec12d00ffe9195b719b9563f to your computer and use it in GitHub Desktop.
Save Mlawrence95/4a88f29aec12d00ffe9195b719b9563f to your computer and use it in GitHub Desktop.
Converts two Pandas dataframes into a two-column latex table. Supports adding a title for each column and an overall title.
import pandas as pd
def latex_two_column_table(title: str, l_caption: str, r_caption: str, l_df: pd.DataFrame, r_df: pd.DataFrame):
"""
Use to print out two-columned LaTeX code (or route into a file) for a set of dataframes
"""
l_df_tex = l_df.to_latex()
r_df_tex = r_df.to_latex()
out = r"""
\hrule
\vspace{{3mm}}
\centering
{}
\vspace{{3mm}}
\hrule
\vspace{{3mm}}
\begin{{tabular}}{{c|c}}
{} & {} \\
{}
&
{}
\end{{tabular}}
""".format(title, l_caption, r_caption, l_df_tex, r_df_tex )
print(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment