Long table and pgfplotstable with multiple data files

I have two csv files: namespgf.csv

Sl. No., Reg. No.,Name,Category,Group,Gate,Sponsored,Department
1,MS001,Ajay-D-Vimal Raj P,PY,OBC,--,No,Physics
2,MS002,Harish Kumar,PY,GE,GATE,Yes,Physics
3,MS003,Ajay-D-Vimal Raj P,PY,OBC,--,No,Physics
4,MS004,Harish Kumar,PY,GE,GATE,Yes,Physics


and markspgf.csv

number,marks
MS001,67
MS002,25
MS003,62
MS004,55


Requirement: I want to print the first file (namespgf.csv) into a long table in which, I would like to include the second column (i.e., marks column) of markspgf.csv, as the column coming after the names column (i.e., as the fourth column).

Here is the MWE (working, but not as I desired)

\documentclass[10pt]{article}
\usepackage[a4paper,margin=2cm]{geometry}
\usepackage{longtable}
\usepackage{pgfplotstable}
\usepackage{array}
\usepackage{filecontents}
%
\begin{filecontents}{namespgf.csv}
1,MS001,Ajay-D-Vimal Raj P,PY,OBC,--,No,Physics
2,MS002,Harish Kumar,PY,GE,GATE,Yes,Physics
3,MS003,Ajay-D-Vimal Raj P,PY,OBC,--,No,Physics
4,MS004,Harish Kumar,PY,GE,GATE,Yes,Physics
\end{filecontents}
%
\begin{filecontents}{markspgf.csv}
number,marks
MS001,67
MS002,25
MS003,62
MS004,55
\end{filecontents}
%
\begin{document}
% ----------------------------------------------------------------------%
\pgfkeys{/pgfplots/table/verb string type}
%
\pgfplotstableset{%
begin table=\begin{longtable},
every first row/.append style={before row={%
%  \caption{The caption}%
\textbf{} & \textbf{Reg. No.} &  \multicolumn{1}{c|}{\textbf{Name}} &
\multicolumn{1}{c|}{\textbf{Category}} & \multicolumn{1}{c|}{\textbf{Group}} & \textbf{GATE} & \textbf{Sponsored} &\textbf{Department} &\textbf{Marks} \\ \hline\hline
%
\multicolumn{9}{c}%
{{\bfseries  Continued from previous page}} \\
\hline%
%
\textbf{} & \textbf{Reg. No.} & \multicolumn{1}{c|}{\textbf{Name}} &
\multicolumn{1}{c|}{\textbf{Category}} & \multicolumn{1}{c|}{\textbf{Group}}  & \textbf{GATE} & \textbf{Sponsored}&\textbf{Department} &\textbf{Marks} \\ \hline\hline
%
\hline \multicolumn{9}{|r|}{{Continued on next page}} \\ \hline
\endfoot
%
\hline
\multicolumn{9}{|r|}{{Concluded}} \\ \hline
\endlastfoot
}},%
end table=\end{longtable},
every last column/.style={%
columns/Name/.style={column type=|p{3cm},string type},
columns/Department/.style={column type=|l,string type},
before row=\hline,after row=\hline}
}%
%--------------------------------------------------------------------------
\pgfplotstablecreatecol[copy column from table={\markspgf}{[index] 1}] {marks} {\namespgf}
%
{\footnotesize
\pgfplotstabletypeset[skip first n=1,outfile=pgfplotstable.multirow.out,%write it to file
]{\namespgf} %%% skip first n=1 NOT WORKING????
} %%% How to tell pgfplotstable not to print the headers from the csv file?
% ----------------------------------------------------------------------%
\end{document}


Here is the output of this code:

Questions:

1. The first row is taken (by pgfplots) from the namespgf.csv file which I do not want. How to tell pgfplotstable not to print the header from file? (I give it myself as in code).

2. How to move the Marks column as fourth column next to Names?

Hope I am clear enough. If any more clarifications are needed please let me know.

-
Please have a look at this answer for my ugly hack and Christian's comment for your first question. – percusse Jul 14 '12 at 11:28
Thanks @percusse. – Harish Kumar Jul 14 '12 at 23:37

In principle, the comment of percusse points into the correct direction: the answer to the first question is to output an empty header row.

To this end, one has to redefine typeset cell such that it generates an empty value into @cell content. The unstable developer version contains improved support for this request since I read the question linked by percusse in his comment (after I realized that one could not redefine typeset cell inside of every head row ...)

My example below shows how to solve it with the current stable 1.5.1 and how it will be done in the upcoming versions (see below).

The second question can be implemented by means of the columns key: it selects which columns are to be printed - and it also defines the output order.

Here is a (somewhat "more" minimal) example which demonstrates only these keys:

\documentclass{standalone}

\usepackage{pgfplotstable}

\pgfkeysifdefined{/pgfplots/table/output empty row/.@cmd}{
% upcoming releases offer this more convenient option:
\pgfplotstableset{
}
}
}{
% versions up to and including 1.5.1 need this:
\pgfplotstableset{
typeset cell/.append code={%
\ifnum\pgfplotstablerow=-1 %
\pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
\fi
}
}
}
}

\begin{document}

\pgfplotstabletypeset[
% suppress the header row 'col1 col2 col3':
col sep=comma,
columns/col1/.style={string type,column type=r},
columns/col2/.style={string type,column type=l},
columns/col3/.style={string type,column type=l},
]
{
col1,col2,col3
Col A,B,C
The first column,E,F
}

\pgfplotstabletypeset[
col sep=comma,
% change ordering of cols:
columns={col1,col3,col2},
columns/col1/.style={string type,column type=r},
columns/col2/.style={string type,column type=l},
columns/col3/.style={string type,column type=l},
]
{
col1,col2,col3
Col A,B,C
The first column,E,F
}
\end{document}


I defined a local style empty header and dropped in different implementations, depending on whether output empty row is defined or not (it will be defined in the next release after 1.5.1).

-
Thanks Dr. @christian Feuersanger, That was cool and very helpful. May I ask a follow up question? How to put col2 and col3 in the single column like say col2/col3 so that there will be only 2 columns in the final table and second column has both col2 and col3? (while .csv file still has three columns). Thank you very much. – Harish Kumar Jul 14 '12 at 23:36
I'm glad my answer was useful. Please feel free to post a new question such that it is visible for other interested users as well. – Christian Feuersänger Jul 15 '12 at 12:14
I have posted it pl. see Putting multiple columns from csv file into single column while printing the table using pgfplotstable @Christian Feuersänger. – Harish Kumar Jul 15 '12 at 12:33
It seems output empty row isn't defined in 1.6.1. (Instead of empty header, I tried to just use every head row/.style={output empty row} only) – Xiè Jìléi Sep 19 '12 at 0:02
@XièJìléi the manual of pgfplotstable, version 1.6.1 contains examples with output empty row. If something is broken, I would be glad if you could submit a bug to the tracker. – Christian Feuersänger Sep 20 '12 at 19:45