1

I want to read a CSV file from disk and then transpose the table that I read. When I create the table in my document, there is no problem with pgfplotstabletranspose command. However, when I try to read the file from the disk, I get an error as

Package pgfplots Error: Sorry, could not retrieve column 'Label' from table 'attachments/paper_survey.csv'. Please check spelling (or introduce name aliases)..

This is my MWE:

\documentclass[]{article}
\usepackage{pgfplots,pgfplotstable}
\begin{document}

\pgfplotstableread[col sep=semicolon]{% Read the data into a table macro
Label;A;B;C;D;E;F;G;H;I;J;K;L;M;N;O
Yes;0.00;0.20;0.00;0.26;0.11;0.00;;0.49;0.14;0.31;0.03;0.60;0.06;0.06;0.00
No;1.00;0.80;1.00;0.74;0.89;1.00;;0.51;0.86;0.69;0.97;0.40;0.94;0.94;0.00
High;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.26
Medium;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.21
Low;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.53
}\datatable

% \pgfplotstableread[col sep = semicolon]{attachments/paper_survey.csv}\datatable

\pgfplotstabletranspose[string type,
    colnames from=Label,
    input colnames to=Label
]\datatabletransposed{\datatable}

\end{document}

How can I fix this?

1

I have no problem running your data from the attachments subfolder

You may want to check the "G" values since there was an empty yes/no slot and the "O" values are 0

Double check your subfolder/file name are correct since this combination worked for me

mainTeXfolder/attachments/paper_survey.csv

Label;A;B;C;D;E;F;G;H;I;J;K;L;M;N;O
Yes;0.00;0.20;0.00;0.26;0.11;0.00;0.0;0.49;0.14;0.31;0.03;0.60;0.06;0.06;0.00
No;1.00;0.80;1.00;0.74;0.89;1.00;0.0;0.51;0.86;0.69;0.97;0.40;0.94;0.94;0.00
High;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.26
Medium;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.21
Low;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.00;0.53

enter image description here

Since you did not elect plot method I used your same one from a previous question

\documentclass[]{article}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.16}
\begin{document}
\pgfplotstableread[col sep = semicolon]{attachments/paper_survey.csv}\datatable

\begin{tikzpicture}
\pgfplotstabletranspose[string type, colnames from=Label, input colnames to=Label]\datatabletransposed{\datatable}
\begin{axis}[
    xbar stacked, % Stacked horizontal bars
    xmin=0, % Start x axis at 0
    ytick=data, % Use as many tick labels as y coordinates
    yticklabels from table={\datatabletransposed}{Label} % Get the labels from the Label column of the \datatable
]
\addplot [fill=green!70!blue] table [x=Yes, y expr=\coordindex] {\datatabletransposed};
\addplot [fill=red!70!blue] table [x=No, y expr=\coordindex] {\datatabletransposed};
\end{axis}
\end{tikzpicture}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.