BigThonkers / ThonkTools

Revolutionary wrappers for stupid lab stuff.
1 stars 3 forks source link

Need Pandas to LaTeX function #1

Closed munnich closed 5 years ago

munnich commented 5 years ago

Here's a LaTeX table template:

\begin{table}[h] \centering \caption{XXXX} \vspace{11pt} $\begin{array}{l} \textrm{Unsicherheiten:}\ \textrm{XXXX: } \pm XX \textrm{XX}\ \end{array}$ \begin{tabular}{ccc} \toprule \textrm{XXXX}/\textrm{XX} & \textrm{XXXX}/\textrm{XX} & \textrm{XXXX}/\textrm{XX} \ \midrule 2 & 0.26 & 0.23\ \hline 4 & 0.33 & 0.25\ \hline 5 & & 0.3\ \hline 6 & 1.25 & 0.83\ \hline 8 & 3.9 & 0.83\ \hline 9 & 4.75 & 4.6\ \hline 10 & 4.7 &\ \bottomrule \end{tabular} \phantom{$\begin{array}{l} \textrm{Unsicherheiten:}\ \textrm{XXXX: } \pm XX \textrm{XX}\ \end{array}$} \label{Tab:X} \end{table}

munnich commented 5 years ago

Here's how far I've gotten:

def csvtex(fname,caption,tabnum=None):
    import pandas as pd
    data=pd.read_csv(fname,delimiter='\t',index_col=None)
    print('\\begin{{table}}[h]\n\centering\n\caption{{{0}}}\vspace{{11pt}}\n\\begin{{tabular}}{{{1}}}\n\\toprule\n{2} '.format(caption,len(data.columns)*'c',('\\textrm{{{1}}}/\\textrm{{}} & '.format(x) for x in list(data.columns.values))))
    print('\midrule')
    print(data.iat[0,0],'&',data.iat[1,0],'\n\hline')
    print('\\bottomrule\n\end{{tabular}}\n\label{{Tab:{0}}}\n\end{{table}}'.format(tabnum))

The actual data entries still aren't output correctly, though. I think I'll have to ditch pandas to get around it.

munnich commented 5 years ago

The main function is there. No styling/formatting option as of now. No pandas was used.

benjaminbutton13659 commented 5 years ago

Have you considered to use basic? I heard it's the way to go!

ericruijun commented 5 years ago

Ich würde Brainfuck empfehlen