Last active
June 29, 2020 23:59
-
-
Save rob-luke/40ab4a8e3bad7db939ec21c0c309ab7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def summary_to_dataframe(summary): | |
results_as_html = summary.tables[1].as_html() | |
return pandas.read_html(results_as_html, header=0, index_col=0)[0] | |
def expand_summary_dataframe(summary): | |
# Determine new columns | |
new_cols = summary.index[0].split(':') | |
col_names = [] | |
for col in new_cols: | |
col_name = col.split('[')[0] | |
summary[col_name] = 'NaN' | |
col_names.append(col_name) | |
# Fill in values | |
for row_idx, row in enumerate(summary.index): | |
col_vals = row.split(':') | |
for col_idx, col in enumerate(col_names): | |
val = col_vals[col_idx].split('[')[1].split(']')[0] | |
summary[col][row_idx] = val | |
return summary | |
def plot_rlm_summary(rlm_summary): | |
as_df = summary_to_dataframe(rlm_summary) | |
as_df = expand_summary_dataframe(as_df) | |
cols = [ ("red", "blue")[c == "hbo"] for c in as_df["Chroma"]] | |
fig = as_df.plot.scatter(x="condition", y="coef", c=cols) | |
return fig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment