def latex_table(inner_tabular: str, position="H", caption=None, escape_caption=False, label=None, output_filepath=None): table = Table(position=position) table.append(NoEscape(inner_tabular)) if caption: caption_ = caption if escape_caption else NoEscape(caption) table.add_caption(caption_) if label: table.append(NoEscape("\label{{tab:{label}}}".format(label=label))) if output_filepath: table.generate_tex(output_filepath) return table.dumps()
stats.kurtosis(spf_bal_UNEM_1Y.iloc[:, 0].values, axis=0), stats.kurtosis(spf_bal_UNEM_2Y.iloc[:, 0].values, axis=0), ]) spf_desc_stat.iloc[8, :] = np.array([ stats.skew(spf_bal_RGDP_1Y.iloc[:, 0].values, axis=0), stats.skew(spf_bal_RGDP_2Y.iloc[:, 0].values, axis=0), stats.skew(spf_bal_HICP_1Y.iloc[:, 0].values, axis=0), stats.skew(spf_bal_HICP_2Y.iloc[:, 0].values, axis=0), stats.skew(spf_bal_UNEM_1Y.iloc[:, 0].values, axis=0), stats.skew(spf_bal_UNEM_2Y.iloc[:, 0].values, axis=0), ]) # create table object tabl = Table() tabl.add_caption( "Descriptive statistics of the SPF target macroeconomic variables for the euro area" ) tabl.append(NoEscape('\label{tab: spf_Desc_Stats}')) # create tabular object tabr = Tabular(table_spec="l|cc|cc|cc") tabr.add_hline() tabr.add_hline() # header row tabr.add_row( (MultiRow(2, data="Statistic"), MultiColumn(2, align='|c|', data="RGDP"), MultiColumn(2, align='|c|', data="HICP"), MultiColumn(2, align='|c', data="UNEM"))) tabr.add_hline(start=2, end=3, cmidruleoption="lr") tabr.add_hline(start=4, end=5, cmidruleoption="lr") tabr.add_hline(start=6, end=7, cmidruleoption="lr")
proc="multiple", df_name="spf_bal_UNEM_2Y_" + str(w)) # concatenate the tables together spf_multitable = pd.concat([ acc_table_RGDP_1Y, acc_table_RGDP_2Y, acc_table_HICP_1Y, acc_table_HICP_2Y, acc_table_UNEM_1Y, acc_table_UNEM_2Y ], axis=1, join_axes=[acc_table_RGDP_1Y.index]) # create table object tabl = Table() tabl.add_caption( "Performance of forecast combinations of ECB SPF forecasts using the training window of the length: " + str(w)) tabl.append(NoEscape('\label{tab: spf_comb_perf_' + str(w) + '}')) # create tabular object tabr = Tabular(table_spec="c|l" + 6 * "|ccc") tabr.add_hline() tabr.add_hline() # header row tabr.add_row( (MultiRow(3, data="Class"), MultiRow(3, data="Forecast Combination Method"), MultiColumn(6, align='|c|', data="RGDP"), MultiColumn(6, align='|c|', data="HICP"), MultiColumn(6, align='|c', data="UNEM"))) tabr.add_hline(start=3, end=20, cmidruleoption="lr")
def build_latex(metrics: List[Metric], invert=False, caption=""): models, metric_labels, splits = {}, {}, {} score_map = defaultdict(lambda: "-") for metric in metrics: metric_vals = metric() score, metric_label, model_name, split_name = ( metric_vals[SCORE], metric_vals[METRIC_LABEL], metric_vals[MODEL_NAME], metric_vals[SPLIT_NAME], ) metric_labels[metric_label] = 1 models[model_name] = 1 splits[split_name] = 1 score_map[(metric_label, model_name, split_name)] = ("-" if math.isnan(score) else score) models = list(models.keys()) splits = list(splits.keys()) metric_labels = list(metric_labels.keys()) if not invert: model_split_cols = "".join( ["c|" for _ in range(len(models) * len(splits))]) table = Tabular("|c|" + model_split_cols) table.add_hline() row = (MultiRow( 2, data="Metric"), ) if len(splits) > 1 else ("Metric", ) for model_name in models: row += (MultiColumn(len(splits), align="|c|", data=model_name), ) table.add_row(row) table.add_hline(1 if len(splits) == 1 else 2) if (len(splits)) > 1: row = ("", ) for _ in range(len(models)): for split_name in splits: row += (split_name, ) table.add_row(row) table.add_hline() for metric_label in metric_labels: row = (metric_label, ) for model_name in models: for split_name in splits: row += (score_map[(metric_label, model_name, split_name)], ) table.add_row(row) table.add_hline() else: metric_split_labels = "".join( ["c|" for _ in range(len(metric_labels))]) table = Tabular("|c|" if len(splits) == 1 else "|c|c|" + metric_split_labels) table.add_hline() row = (MultiColumn(2, align="|c|", data=""), ) if len(splits) > 1 else ("", ) for metric_label in metric_labels: row += (metric_label, ) table.add_row(row) table.add_hline() for model_name in models: row = (MultiRow(len(splits), data=model_name), ) for split_name in splits: row += (split_name, ) for metric_label in metric_labels: row += (score_map[(metric_label, model_name, split_name)], ) table.add_row(row) if len(splits) > 1: table.add_hline(start=2) row = ("", ) table.add_hline() latex_table = Table(position="h") latex_table.append(table) latex_table.add_caption(caption) return latex_table
def gen_tex_table(tbl, cap, file_name, r): """ The function creates a tex file to which it export the given table from python. Parameters ---------- tbl : DataFrame DataFrame containing the table to be exported. cap : Str Table caption. file_name : Str Name of the tex file in the "Tables" directory. r : Int Number of decimals to round up the metrics. """ # create tabule object tabl = Table() tabl.add_caption(cap) tabl.append(NoEscape("\label{tab: " + cap + "}")) # create tabular object tabr = Tabular(table_spec="lccc") tabr.add_hline() tabr.add_hline() # header row tabr.add_row(["Forecast Combination Method"] + list(tbl)) tabr.add_hline() # number of combination methods + additional rows R = tbl.shape[0] # specify format fmt = "{:." + str(r) + "f}" # fill in the rows for each combination method (-3 for individuals) for i in range(R-3): tabr.add_row([tbl.index[i]] + [ fmt.format(item) for item in tbl.iloc[i, :]]) tabr.add_hline() # additional rows for i in range(R-3, R): tabr.add_row([tbl.index[i]] + [ fmt.format(item) for item in tbl.iloc[i, :]]) # end of table tabr.add_hline() tabr.add_hline() # add tabular to table tabl.append(tabr) # export the table tabl.generate_tex("C:/Users/Marek/Dropbox/Master_Thesis/Latex/Tables/" + file_name) return
ret_desc_stat = pd.DataFrame(data=np.full((9, 4), np.nan, dtype=np.float), columns=tickers, index=ds_stats) ret_desc_stat.iloc[0, :] = np.mean(ret.values, axis=0) ret_desc_stat.iloc[1, :] = np.median(ret.values, axis=0) ret_desc_stat.iloc[2, :] = stats.mode(ret.values, axis=0)[0] ret_desc_stat.iloc[3, :] = np.std(ret.values, axis=0) ret_desc_stat.iloc[4, :] = np.var(ret.values, axis=0) ret_desc_stat.iloc[5, :] = np.min(ret.values, axis=0) ret_desc_stat.iloc[6, :] = np.max(ret.values, axis=0) ret_desc_stat.iloc[7, :] = stats.kurtosis(ret.values, axis=0) ret_desc_stat.iloc[8, :] = stats.skew(ret.values, axis=0) # create table object tabl = Table() tabl.add_caption( "Descriptive statistics of log-returns of U.S. Treasury futures") tabl.append(NoEscape('\label{tab: Bond_ret_Desc_Stats}')) # create tabular object tabr = Tabular(table_spec="lcccc") tabr.add_hline() tabr.add_hline() # header row tabr.add_row(["Statistic"] + tickers) tabr.add_hline() # fill in the rows of tabular for i in range(9): tabr.add_row([ds_stats[i]] + ["{:.7f}".format(item) for item in ret_desc_stat.iloc[i, :]]) # end of table tabr.add_hline() tabr.add_hline()
np.transpose(X), y])[-2:] # randomization inference p-values p = np.mean(abs(beta_original) <= abs(beta_dist), axis=0) # fill the output table output_table.iloc[:, [4, 6]] = beta_original.reshape((3, 2)) output_table.iloc[:, [5, 7]] = p.reshape((3, 2)) ######################## # Printing output table# ######################## # create tabule object tabl = Table() tabl.add_caption( "Estimates of the effects of changing price rules on differents variables for both categories along with the p-values from the randomization inference." ) tabl.append(NoEscape("\label{tab: output_table}")) # create tabular object tabr = Tabular(table_spec="l|cc|cc|cc|cc") tabr.add_hline() tabr.add_hline() # header row tabr.add_row((MultiRow(3, data="Dependent Variable"), MultiColumn(4, align='|c|', data="Mobile Phones"), MultiColumn(4, align='|c', data="Water Heaters"))) tabr.add_hline(start=2, end=9, cmidruleoption="lr") tabr.add_row( ("", MultiColumn(2, align='|c|', data="Pilot 1"),