Sharedlatex-tests / data.texOpen in CoCalc
\documentclass{article}
\usepackage{amsmath}
\usepackage{sagetex}
\usepackage{booktabs}

\begin{document}

Why is the table showing up here, above the sageblock?


\begin{sageblock}
t = r"""
\begin{tabular}{ll}
col1 & col2 \\
1    & 2 \\
3    & 4 via sagestr
\end{tabular}
"""
\end{sageblock}

You just want to include \verb|t| without applying latex(), so use
\verb|\sagestr|, not \verb|\sage|.

\sagestr{"foo"}

\sagestr{t}

\section{t2: join(list of str)}

\begin{sageblock}
t2 = []
t2.append(r"\begin{tabular}{ll}")
t2.append(r"col1 & col2 \\")
t2.append(r"1    & 2 \\")
t2.append(r"3    & 4")
t2.append(r"\end{tabular}")
t2 = "\n".join(t2)
\end{sageblock}

\sagestr{t2}

\section{pandas: DataFrame.to\_html()}

\begin{sageblock}
import statsmodels.api as sm
import pandas as pd
ds = sm.datasets.grunfeld.load_pandas()
pt = ds.data[ds.data.year > 1950]\
    .pivot_table(\
        values=["invest"],\
        index=["firm"],\
        columns=["year"])
\end{sageblock}

%\sage{ds.data.head().to_latex()}

Dan: The following uses toprule, midrule, and bottomrule, which require the booktabs package.

HSY: Ah, thanks, that's really good. I want to demo this to a company who is interested in SMC. Showing them that creating tables is easy, is my goal.

\sagestr{pt.to_latex()}

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x



\end{document}