1

I am using \csvreader to print out a table. However, one of the fields contains a lot of comma

\begin{filecontents*}{sairis7.csv}
weights, accuracy,  duration
[0.3837762, 0.3441996, 0.6423321, 0.480776],    00:03:55.18,    95.9106552963
[0.7841548, 0.5516101, 0.3033666, 0.1603187],   00:03:53.79,    92.6795811851
[0.3249006, 0.4728797, 0.3725799, 0.996232],    00:04:19.29,    95.2666745935
[0.1699597, 0.5566617, 0.9622979, 0.051388],    00:04:50.01,    95.8973879383
[0.4532285, 0.3019645, 0.6935862, 0.8012383],   00:04:33.44,    95.4078896272
[0.1580461, 0.4561823, 0.613519, 0.0955829],    00:05:09.47,    95.6631033785
[0.5424764, 0.621894, 0.7174977, 0.5827319],    00:04:27.20,    95.8742075138
[0.3560077, 0.346697, 0.6691461, 0.9715148],    00:04:04.99,    95.6211843553
[0.4464995, 0.95631, 0.5825031, 0.4944645], 00:04:11.69,    95.6329624721
[0.9851933, 0.4518537, 0.5542809, 0.9837232],   00:04:23.49,    95.1412451035
\end{filecontents*}

and when I call in the tex with

\begin{table}
\caption{SA-WKNN for the Iris Dataset}
\csvreader[longtable=lllllc,
    table head= Weights & Accuracy & Duration (in hr:min:sec)\\\hline,
    late after line=\\\hline]% 
{sairis7.csv}{weights = \w, accuracy = \a, duration = \d}%
{\w & \a & \d }%
\label{tab:label}
\end{table}

it prints nothing

enter image description here

How can I make it skip the commas found in the weight field so that it will print the weights column?

2
  • Welcome to TeX SE! Some clarifications are needed: 1) I think the Duration/Accuracy columns should be inverted, no? 2) Should the numbers in the Weights column be aligned vertically?
    – Alenanno
    Commented Aug 14, 2016 at 13:18
  • @RunarTrollet got the format that I wanted. However, I am getting some errors when I integrate it to my whole tex file. It says: Package pgfkeys Error: I do not know the key '/csv head/weights', to which yo u passed '\w ', and I am going to ignore it. Perhaps you misspelled it..
    – Mestica
    Commented Aug 14, 2016 at 13:43

1 Answer 1

2

You are of course right that csvsimple would interpret the , as column-seperators. If it is okey to change your csv-file, this solution should work.

You can assign a different symbol for column-separation, which is described in the documentation of cvsimple, section 3.6 Separators:

/csv/separator=⟨sign⟩

Sets the ⟨sign⟩ which is treates as separator between the data values of a data line.

Note that you can always locate the documentation using the command-line/terminal by writing texdoc csvsimple, and that works for any package. The documentation is also available at http://ctan.org/pkg/csvsimple

Output

enter image description here

Code

\documentclass[11pt]{article}
\usepackage{filecontents}
\begin{filecontents*}{sairis7.csv}
weights;accuracy; duration
[0.3837762, 0.3441996, 0.6423321, 0.480776];   00:03:55.18;   95.9106552963
[0.7841548, 0.5516101, 0.3033666, 0.1603187];  00:03:53.79;   92.6795811851
[0.3249006, 0.4728797, 0.3725799, 0.996232];   00:04:19.29;   95.2666745935
[0.1699597, 0.5566617, 0.9622979, 0.051388];   00:04:50.01;   95.8973879383
[0.4532285, 0.3019645, 0.6935862, 0.8012383];  00:04:33.44;   95.4078896272
[0.1580461, 0.4561823, 0.613519, 0.0955829];   00:05:09.47;   95.6631033785
[0.5424764, 0.621894, 0.7174977, 0.5827319];   00:04:27.20;   95.8742075138
[0.3560077, 0.346697, 0.6691461, 0.9715148];   00:04:04.99;   95.6211843553
[0.4464995, 0.95631, 0.5825031, 0.4944645], 00:04:11.69;   95.6329624721
[0.9851933, 0.4518537, 0.5542809, 0.9837232];  00:04:23.49;   95.1412451035
\end{filecontents*}

\usepackage{csvsimple}
\usepackage{longtable}

\begin{document}

\begin{table}
\caption{SA-WKNN for the Iris Dataset}
\csvreader[longtable=lllllc,
    separator=semicolon,
    table head= Weights & Accuracy & Duration (in hr:min:sec)\\\hline,
    late after line=\\\hline]% 
{sairis7.csv}{weights = \w, accuracy = \a, duration = \d}%
{\w & \a & \d }%
\label{tab:label}
\end{table}

\end{document}
3
  • I am getting an error Package pgfkeys Error: I do not know the key '/csv head/weights', to which yo u passed '\w ', and I am going to ignore it. Perhaps you misspelled it.. Why does this happen?
    – Mestica
    Commented Aug 14, 2016 at 13:35
  • I think it is because you havent overwritten the file with new data. add \usepackage{filecontents} to your preamble, which enables this functionality.
    – Runar
    Commented Aug 14, 2016 at 13:41
  • Your correct, I deleted the sairis7.csv file first in the code's folder so that it will generate a new sairis7.csv with the semicolon as its separator.
    – Mestica
    Commented Aug 14, 2016 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .