Skip to content

Instantly share code, notes, and snippets.

@Mlawrence95
Mlawrence95 / dataframes_to_latex_columns.py
Last active November 5, 2019 23:17
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()
@Mlawrence95
Mlawrence95 / confusion_matrix.py
Last active March 26, 2024 10:25
Python: create a confusion matrix across two columns in a Pandas dataframe having only categorical data
import pandas as pd
def confusion_matrix(df: pd.DataFrame, col1: str, col2: str):
"""
Given a dataframe with at least
two categorical columns, create a
confusion matrix of the count of the columns
cross-counts
use like: