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

.. only:: html

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

        Click :ref:`here <sphx_glr_download_examples_dataframe.py>`
        to download the full example code

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

.. _sphx_glr_examples_dataframe.py:


Extracting data and labels from a :class:`~pandas.DataFrame`
============================================================

:class:`~pandas.DataFrame`\s can be used similarly to any other kind of input.
Here, we generate a scatter plot using two columns and label the points using
a third column.

.. GENERATED FROM PYTHON SOURCE LINES 9-28



.. image-sg:: /examples/images/sphx_glr_dataframe_001.png
   :alt: dataframe
   :srcset: /examples/images/sphx_glr_dataframe_001.png
   :class: sphx-glr-single-img





.. code-block:: default


    from matplotlib import pyplot as plt
    import mplcursors
    from pandas import DataFrame


    df = DataFrame(
        [("Alice", 163, 54),
         ("Bob", 174, 67),
         ("Charlie", 177, 73),
         ("Diane", 168, 57)],
        columns=["name", "height", "weight"])

    df.plot.scatter("height", "weight")
    mplcursors.cursor().connect(
        "add", lambda sel: sel.annotation.set_text(df["name"][sel.index]))
    plt.show()

    # test: skip


.. _sphx_glr_download_examples_dataframe.py:


.. only :: html

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



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

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



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

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


.. only:: html

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

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