Although an accepted answer is posted, I would also offer the option to use DataTool. I kept the raw \DTLfetch command exposed. it could be encapsulated in its own macro to achieve your objective.
\documentclass{article}
% datatool does the database work
\usepackage{datatool}
% the file contents
\begin{filecontents*}{values.csv}
color, N, n_trees, M
red, 200, 100, 50
green, 300, 10, 49
blue, 400, 1, 48
\end{filecontents*}
% load the database to the document
\DTLloaddb{values}{values.csv}
\begin{document}
% examples
The trees for red is: \DTLfetch{values}{color}{red}{n_trees}.
The M for blue is: \DTLfetch{values}{color}{blue}{M}.
The color that had 1 tree is: \DTLfetch{values}{n_trees}{1}{color}.
\end{document}
See also a different example at this link.
readarraypackage: https://www.ctan.org/pkg/readarray – Steven B. Segletes Jan 16 '20 at 12:41