# Combine columns of a csv

I'm attempting to use \pgfplotstabletypeset but with no luck. I have a CSV file like the following:

Name, Age, stDev


When I output in this into my PDF, I would like the last two columns be combined such that I end up with 15 +/- 3. I would also like to name that column Age.

I don't know how to do it using pgfplotstable, but here's how to do it with datatool:

Edit: Updated to round to 2 d.p.

\documentclass{article}

\usepackage{datatool}

\begin{filecontents*}{test.csv}
Name, Age, stDev
\end{filecontents*}

% Round to 2 dp and display.
% (More efficient to use \dtlround rather than \DTLround as the
% data doesn't involve currencies so no conversion is needed)
\newcommand{\round}[1]{\dtlround{#1}{#1}{2}#1}

\begin{document}

\begin{tabular}{ll}
\bfseries Name & \bfseries Age%
\DTLforeach{mydata}{\Name=Name,\Age=Age,\stDev=stDev}%
{%
\\\Name & $\round\Age\pm\round\stDev$
}%
\end{tabular}

\end{document}


Result:

• just a side question, how would you control the precision? in my actual csv file, there are 4 d.p., I need only 2 – sachinruk Jul 9 '13 at 0:58
• @Sachin_ruk I've edited the example to include rounding to 2 d.p. – Nicola Talbot Jul 9 '13 at 7:25

You need to create a column specification for that.

\documentclass{article}
\usepackage{pgfplotstable}

Name, Age, stDev
Eve, 12, 1
}\mytable

\begin{document}
\pgfplotstabletypeset[
create on use/unc age/.style={
create col/assign/.code={%
\edef\entry{\thisrow{Age}$\pm$\thisrow{stDev}}
\pgfkeyslet{/pgfplots/table/create col/next content}{\entry}
}
},
columns={Name,unc age},
columns/unc age/.style={column name=Age},
string type
]\mytable

\end{document}