# Replace Column in PGFPlotstable with lookup values

I have a table that has a column of integer values representing atomic numbers. I know of the command:

string replace={---}{\textemdash}

However this is table-wide. I want to match the values in a specific column, and replace it with a lookup value. Either through multiple replace statements (I will only be dealing with a few integers: 1,6,7,8,16 I think are the only possible integers I'll need). Or preferably through some sort of lookup table.

Is there a method for this type of substitution. I can rewrite the python script that generates these tables, but they are spread across many locations, and it would be considerable effort to pull together a whole new set of them for this single purpose. I would like to replace the values found in the atomicnum column. I've included a sample csv file below:

atomnum,atomicnum,x,y,z
1,6,0.000001,0.700530,-1.910890 2,6,0.000001,1.438902,-0.717628
3,6,0.000000,0.696419,0.453609 4,6,0.000000,-0.696419,0.453609
5,6,-0.000001,-1.438902,-0.717628 6,6,-0.000001,-0.700530,-1.910890
7,1,0.000001,1.224386,-2.862243 8,1,0.000002,2.524808,-0.733291
9,6,0.000001,-0.786842,1.970076 10,1,0.890609,-1.241092,2.412264
11,6,-0.000001,0.786842,1.970076 12,1,0.890605,1.241095,2.412266
13,1,-0.890609,1.241092,2.412264 14,1,-0.890605,-1.241095,2.412266
15,1,-0.000002,-2.524808,-0.733291 16,1,-0.000001,-1.224386,-2.862243


The table that pgfplotstable would "see" would be substituted according a pseudocode array like the following:

temp[] = {1=>"H", 6=>"C", 7=>"N", 8=>"O", 16=>"S"}

The table used and output is then:

atomnum,atomicnum,x,y,z
1,C,0.000001,0.700530,-1.910890
2,C,0.000001,1.438902,-0.717628
3,C,0.000000,0.696419,0.453609
4,C,0.000000,-0.696419,0.453609
5,C,-0.000001,-1.438902,-0.717628
6,C,-0.000001,-0.700530,-1.910890
7,H,0.000001,1.224386,-2.862243
8,H,0.000002,2.524808,-0.733291
9,C,0.000001,-0.786842,1.970076
10,H,0.890609,-1.241092,2.412264
11,C,-0.000001,0.786842,1.970076
12,H,0.890605,1.241095,2.412266
13,H,-0.890609,1.241092,2.412264
14,H,-0.890605,-1.241095,2.412266
15,H,-0.000002,-2.524808,-0.733291
16,H,-0.000001,-1.224386,-2.862243

-

You can apply the substitution local to the column if I get your question correctly.

\documentclass{standalone}
\usepackage{pgfplots,pgfplotstable}
atomnum,atomicnum,x,y,z
1,6,0.000001,0.700530,-1.910890
2,6,0.000001,1.438902,-0.717628
3,6,0.000000,0.696419,0.453609
4,6,0.000000,-0.696419,0.453609
5,6,-0.000001,-1.438902,-0.717628
6,6,-0.000001,-0.700530,-1.910890
7,1,0.000001,1.224386,-2.862243
8,1,0.000002,2.524808,-0.733291
9,6,0.000001,-0.786842,1.970076
10,1,0.890609,-1.241092,2.412264
11,6,-0.000001,0.786842,1.970076
12,1,0.890605,1.241095,2.412266
13,1,-0.890609,1.241092,2.412264
14,1,-0.890605,-1.241095,2.412266
15,1,-0.000002,-2.524808,-0.733291
16,1,-0.000001,-1.224386,-2.862243
}\mytable
\begin{document}
\pgfplotstabletypeset[
columns/atomicnum/.append style={string type},
columns/atomicnum/.append style={string replace={6}{C}},
columns/atomicnum/.append style={string replace={1}{H}},
columns/x/.append style={dec sep align},
columns/y/.append style={dec sep align},
columns/z/.append style={dec sep align},
]\mytable
\end{document}


-
Wonderful! That is exactly what I needed to know. I have to say, the documentation for pgfplots and pgfplotstable is massive, frightening and confusing :/ –  J M Sep 4 '12 at 17:47
@JM No problem. I would really recommend checking the TikZ/PGF manual for the key-value system. Then I'm sure you can appreciate the manual much more. –  percusse Sep 4 '12 at 18:25