[Tex/LaTex] Importing table from csv file

csvpgfplotstabletables

I have the following table in a avg_value.csv file:

,M23,F23_1,M36,F44,F63,M70
M23,1.00,0.81,0.88,0.83,0.41,0.82
F23_1,,1.00,0.52,0.56,0.25,0.94
M36,,,1.00,0.62,0.94,0.96
F44,,,,1.00,0.43,0.23
F63,,,,,1.00,0.22
M70,,,,,,1.00

and I want to import it in my LaTeX file.
Currently, I am using this code from http://pgfplots.sourceforge.net/gallery.html :

\usepackage{pgfplots}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\usepackage{array}
.
.
.
\pgfplotstabletypeset[
every head row/.style={
before row=\toprule,after row=\midrule},
every last row/.style={
after row=\bottomrule},
]
{pgfplotstable.avg_value.csv}

In fact, I do not import anything.

I receive as output message from kile:

! Package pgfplots Error: Could not read table file
'pgfplotstable.avg_value.csv'.


Changing the code as follows:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pagestyle{empty}

\usepackage{pgfplotstable}
\usepackage{array}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{pgfplotstable}

\begin{document}

\begin{table}
\pgfplotstableread[col sep=comma]{pgfplotstable.avg_value.csv}\mytable
\pgfplotstabletypeset[
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
display columns/0/.style={string type,column name={}}
]
{\mytable}
\caption[title.]{title.}
\label{tab:foo} 
\end{table}

\end{document}

did not solve the problem. Nothing really appears.

Best Answer

You have to describe the structure of the csv file to pgfplotstable. And you have subscripts in your column/row names that you need to take care of. I've just removed them.

\documentclass{scrreprt}
\usepackage{pgfplotstable,booktabs}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% You don't need this part
% I did it to create your file 
\usepackage{filecontents} % <-- To create files on the fly

\begin{filecontents*}{avg_value.csv}
,M23,F231,M36,F44,F63,M70
M23,1.00,0.81,0.88,0.83,0.41,0.82
F231,,1.00,0.52,0.56,0.25,0.94
M36,,,1.00,0.62,0.94,0.96
F44,,,,1.00,0.43,0.23
F63,,,,,1.00,0.22
M70,,,,,,1.00
\end{filecontents*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\pgfplotstabletypeset[
col sep = comma,
string replace*={_}{\textsubscript},
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
display columns/0/.style={string type,column name={}}
]
{avg_value.csv}

\end{document}

enter image description here

Please have a look at the manual for a quickstart if you need to get a feeling for common options.