Edit See the edit history for the incomplete answer.
What I did is to run over the
Reg.No.
entries and try to see if there is a match in the
number
column of
\markspgf
table. If there is, then we use the
marks
value of that row in creating the new column, otherwise we put a
N/A
. (if not needed this can be skipped). Then, we record the counter value since
\pgfplotstablerow
variable is not available now so we keep track of the rows that failed to be matched with and increment the counter.
When the numbers are exhausted, we use this new column in the new table and we again check at each row whether this row is to be used or not. If the row number is matched with the first number on the list, we trigger the if condition with \pgfplotsuserowfalse
otherwise nothing happens and the row is typeset.
\documentclass{article}
\usepackage{pgfplotstable,xstring}
\usepackage{filecontents,etoolbox}
%
\begin{filecontents}{namespgf.csv}
Reg.No.,Name,Place
5501,Kathirvelu A,re
5502,Gugan K,rt
5503,Kalaitchelvi S,uy
5504,Suresh S,itr
5505,Mahesh K,utyehd
5506,Balini N,utyehd
5507,Kumar H,utyehd
5508,Khalate A,utyehd
5509,me,hgte
5510,you,there
5511,them,here
5512,who,where
\end{filecontents}
%
\begin{filecontents}{markspgf.csv}
number,marks
5501,67
5502,25
5503,62
5505,95
5507,100
5512,45
\end{filecontents}
\def\marksuccess{}
\def\mypopulatedlist{}
\newcounter{myrowcount}
\setcounter{myrowcount}{0}
\begin{document}
%=============================================================================
\pgfplotstableread[col sep=comma]{namespgf.csv}\namespgf
\pgfplotstableread[col sep=comma,verb string type]{markspgf.csv}\markspgf
%
\pgfkeys{/pgfplots/table/verb string type}
% ----------------------------------------------------------------------%
\pgfplotstablecreatecol[
create col/assign/.code={%
\let\marksuccess\relax
\pgfplotstableforeachcolumnelement{number}\of\markspgf\as\cellb{%
\IfStrEq{\thisrow{Reg.No.}}{\cellb}{%True
\pgfplotstablegetelem{\pgfplotstablerow}{marks}\of\markspgf
\edef\myretval{\pgfplotsretval}
\def\marksuccess{1}
%\breakforeach %This would have saved some time if it was available
}
{}%False
}
\if\marksuccess\relax
\def\myretval{N/A}%
\xappto\mypopulatedlist{\arabic{myrowcount},}
\else
\fi
\stepcounter{myrowcount}
\pgfkeyslet{/pgfplots/table/create col/next content}\myretval
}]{Marks}\namespgf
\pgfplotstabletypeset[
column type=l,
columns={Reg.No.,Name,Marks},
row predicate/.code={%
\StrBefore{\mypopulatedlist}{,}[\mynextrow] %Look at the first number before the comma on the list
\IfStrEq{#1}{\mynextrow}{%If the current row is equal to that number
\StrLen{\mynextrow}[\numberlength]%Get the length of the number
\StrGobbleLeft{\mypopulatedlist}{\number\numexpr\numberlength+1\relax}[\mytemplist]%Delete this number and the next comma from the list
\edef\mypopulatedlist{\mytemplist}%Overwrite the old list with the new
\pgfplotstableuserowfalse% Tell pgfplots to omit this row
}{}
}
]\namespgf
\end{document}
Starting with version 1.6 of PGFPlots (I think), a new key output empty row
has become available that suppresses printing of a row. This can be used in your style:
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\begin{document}
\pgfplotstabletypeset[
col sep=&, header=false,
every head row/.style={
output empty row,
before row={%
\toprule
Facteurs & \multicolumn{5}{c}{Niveaux}\\
}
},
every last row/.style={
after row=\bottomrule
},
display columns/0/.style={string type}
]
{%
\pgfutilensuremath{\chi} & 8 & 11 & 14 & &
5 & 8 & 11 & 14 & 45 & 2.456
q & 8 & 11 & 14 & & 3
x & 8 & 11 & 14 & 5612345 & 4
b & 8 & 11 & 14 & & 5
}
\end{document}
If you're using an earlier version and can't / don't want to update, here's a slightly brutish workaround. You can add the code
\makeatletter
\pgfplotsset{
/pgfplots/table/omit header/.style={%
/pgfplots/table/typeset cell/.append code={%
\ifnum\c@pgfplotstable@rowindex=-1
\pgfkeyslet{/pgfplots/table/@cell content}\pgfutil@empty%
\fi
}
}
}
\makeatother
in your preamble, which makes a style omit header row
available. If you use that key in \pgfplotstable
, the output routine for each table cell will be amended with a check whether we're in row number -1
(the header row), and if we are, no output is generated.
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\makeatletter
\pgfplotsset{
/pgfplots/table/omit header/.style={%
/pgfplots/table/typeset cell/.append code={%
\ifnum\c@pgfplotstable@rowindex=-1
\pgfkeyslet{/pgfplots/table/@cell content}\pgfutil@empty%
\fi
}
}
}
\makeatother
\begin{document}
\pgfplotstabletypeset[
col sep=&,
header=false,
every head row/.style={
before row={%
\toprule
Facteurs & \multicolumn{5}{c}{Niveaux}\\
}
},
every last row/.style={
after row=\bottomrule
},
display columns/0/.style={string type},
omit header
]
{%
\pgfutilensuremath{\chi} & 8 & 11 & 14 & &
5 & 8 & 11 & 14 & 45 & 2.456
q & 8 & 11 & 14 & & 3
x & 8 & 11 & 14 & 5612345 & 4
b & 8 & 11 & 14 & & 5
}
\end{document}
Best Answer
Ahhh I found it, pretty simple actually: I start the tabe with the attribute 'columns/a/.style={reset styles,string type}' :
Where 'a' is the name of my first column !
Hope this helps someone else ;)