# Transposing a table and setting row labels manually

I am new on this forum and have a question about transposing data with the pgfplotstable package. I have found a post explaining how to transpose a table and have tried to make modifications using the documentation but I am not managing to find the right commands.

I have an input CSV file which contains a series of values (one line only):

2016-06-13 05:00,6.2,5305,849,29.0,160,1,160

I want to use LaTeX

2. generate a vertical table with the values, and
3. assign an arbitrary name for each line of the output table.

The code I have for this:

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}

\begin{document}

col sep=comma,
]{test.csv}\normal

\pgfplotstabletranspose[
input colnames to={colA,colB}
]\transpose\normal

%\begin{center}
\pgfplotstabletypeset[
string type,
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
every col no 0/.style={
column type={l},
column name={Averages for the week},
%postproc cell content/.append style={/pgfplots/table/@cell content/.add={Subj }{}},
},
]\transpose

\end{document}


With this code, I get a table with only one column (and some text appended at the end of the last row "index7"), whereas I would like to have something like this (where I define in the TEX file names for each rows:

Is it possible to do this?

• Welcome to TeX.SX!! Nice question. Rather than posting code fragments it is better to post a full minimal working example. A MWE should start with a \documentclass command, have a minimal preamble and then \begin{document}...\end{document}. The code should compile and be as small as possible to demonstrate your problem. This makes it much easier for people to help you --- and much more likely that they will! – Andrew Aug 8 '16 at 10:40

Maybe something like this:

\documentclass{article}
\begin{filecontents*}{mydata.dat}
2016-06-13 05:00,6.2,5305,849,29.0,160,1,160
\end{filecontents*}
\setstackEOL{,}
\renewcommand\stackalignment{r}
\def\sepdata#1,#2\relax{\def\Week{#1}\def\datalist{#2}}
\begin{document}
\begin{tabular}{lr}
\toprule
Averages for the week starting & \Week\\
\midrule
\Longstack[l]{Row Name1,
Row Name2,
Row Name3,
Row Name4,
Row Name5,
Row Name6,
Row Name7} &
\expandafter\Longstack\expandafter{\datalist}\\
\bottomrule
\end{tabular}
\end{document}


It is possible using \pgfplotstable, just very very difficult.

\documentclass{article}
\usepackage{pgfplotstable,filecontents,booktabs}
\begin{filecontents*}{test.dat}
2016-06-13 05:00,6.2,5305,849,29.0,160,1,160
\end{filecontents*}

\begin{document}
Averages for week starting,RowName1,RowName2,RowName3,RowName4,RowName5,RowName6,RowName7
}\names% create column names
\fbox{\pgfplotstabletypeset[string type]\names}% debug

col sep=comma,
string type
]{test.dat}\normal
\fbox{\pgfplotstabletypeset[string type]\normal}% debug

\pgfplotstablegetelem{0}{0}\of\normal
\let\mydate=\pgfplotsretval% will become column name later
\mydate% debug

\pgfplotstablevertcat\names\normal
\fbox{\pgfplotstabletypeset[string type,]\names}% debug