[Tex/LaTex] One of the fields in the csv read by csvreader has a lot of comma

csvcsvsimple

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?

Best Answer

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}