1

I don't know why the data rows not shows up. Only the header, here is my csv file:

method,name,error,occurences
socket,socket,"ConnectionResetError(54, 'Connection reset by peer')",12
socket,socket,"CryptoError('Decryption failed. Ciphertext failed verification',)",60
socket,socket,"SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:748)')",77
socket,socket,"ConnectionRefusedError(61, 'Connection refused')",992
socket,socket,"BrokenPipeError(32, 'Broken pipe')",3

And my MWE:

\begin{document}
\usepackage{csvsimple}
\usepackage{datatool}  
\begin{table}[h]
    \centering
    \caption[Table~\ref{fig:socketdropconnerr} Error during socket test]{Error during socket test}
    \vspace{0.2cm}    
    \label{fig:drop-error-socket}
    \begin{tabular}{ l l }%
        \toprule error & occurences \\
        \csvreader[head to column names]{csv/dropped-conn/error-socket.csv}{}%
        {\\\hline\error & \occurences}%
        \\\hline
    \end{tabular}
\end{table}
\end{document}
0

The problem seems to be the content of your error column. The package seems to not understand the stuff contained in surrounding "s to be one cell. The result is that it ignores the lines it can't parse, and since this is true for all lines, every line is ignored.

Instead of using " to denote a cell containing commas, use curly brackets. Also the underscore doesn't work here, you'd have to escape it using \. The following would work:

CSV:

method,name,error,occurences
socket,socket,{ConnectionResetError(54, 'Connection reset by peer')},12
socket,socket,{CryptoError('Decryption failed. Ciphertext failed verification',)},60
socket,socket,{SSLEOFError(8, 'EOF occurred in violation of protocol (\_ssl.c:748)')},77
socket,socket,{ConnectionRefusedError(61, 'Connection refused')},992
socket,socket,{BrokenPipeError(32, 'Broken pipe')},3

TeX:

\documentclass{article}
\usepackage{csvsimple}
\usepackage{datatool}  
\usepackage{booktabs}

\begin{document}
\begin{table}[h]
    \centering
    \caption[Table~\ref{fig:socketdropconnerr} Error during socket test]{Error during socket test}
    \vspace{0.2cm}    
    \label{fig:drop-error-socket}
    \begin{tabular}{ l l }%
        \toprule error & occurences \\
        \midrule
        \csvreader[late after line=\\,head to column
        names]{data3.csv}{}%
        {\error & \occurences}%
        \bottomrule
    \end{tabular}
\end{table}
\end{document}

enter image description here

  • Why even use csvsimple here? datatool can read the data just fine, all extra needed is to escape that _ – daleif Jan 22 '18 at 8:39
  • @daleif because he used csvsimple and asked why it doesn't work. And take a look at egreg's answer for that underscore (didn't know that, just took a quick look into the documentation when I wrote my answer). – Skillmon Jan 22 '18 at 8:47
2

If entries of the CSV file contain commas, it's best to use a different separator.

\begin{filecontents*}{\jobname.csv}
method;name;error;occurences
socket;socket;ConnectionResetError(54, 'Connection reset by peer');12
socket;socket;CryptoError('Decryption failed. Ciphertext failed verification',);60
socket;socket;SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:748)');77
socket;socket;ConnectionRefusedError(61, 'Connection refused');992
socket;socket;BrokenPipeError(32, 'Broken pipe');3
\end{filecontents*}

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{csvsimple}

\begin{document}

\begin{table}[htp]
\centering
\caption{Error during socket test}
\label{fig:drop-error-socket}

\vspace{0.2cm}    

\csvreader[
  head to column names,
  separator=semicolon,
  tabular=ll,
  table head=\toprule error & occurrences \\ \midrule,
  table foot=\bottomrule,
  respect underscore,
]{\jobname.csv}{}
{\error & \occurences}

\end{table}

\end{document}

See also the respect underscore option for avoiding problems with _.

I used filecontents* only to make the example self-contained.

enter image description here

  • Did not know that extra option, though datatool does not seem to have issues with the original data (at least after escaping the _) – daleif Jan 22 '18 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.