
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/composition/eval_csv.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_composition_eval_csv.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_composition_eval_csv.py:

Transformer for evaluating csv.lark

.. GENERATED FROM PYTHON SOURCE LINES 2-27

.. code-block:: Python


    from lark import Transformer

    class CsvTreeToPandasDict(Transformer):
        INT = int
        FLOAT = float
        SIGNED_FLOAT = float
        WORD = str
        NON_SEPARATOR_STRING = str

        def row(self, children):
            return children

        def start(self, children):
            data = {}

            header = children[0].children
            for heading in header:
                data[heading] = []

            for row in children[1:]:
                for i, element in enumerate(row):
                    data[header[i]].append(element)

            return data


.. _sphx_glr_download_examples_composition_eval_csv.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: eval_csv.ipynb <eval_csv.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: eval_csv.py <eval_csv.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: eval_csv.zip <eval_csv.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
