.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/prog/plot_pandas_groupby.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_prog_plot_pandas_groupby.py: ================= Pandas et groupby ================= Petit tour de passe passe autour d'un :meth:`pandas.DataFrame.groupby` et des valeurs manquantes qui ne sont plus prises en compte depuis les dernières versions. groupby et valeur manquantes ============================ .. GENERATED FROM PYTHON SOURCE LINES 14-24 .. code-block:: Python import pandas data = [{"a": 1, "b": 2}, {"a": 10, "b": 20}, {"b": 3}, {"b": 4}] df = pandas.DataFrame(data) df .. raw:: html
a b
0 1.0 2
1 10.0 20
2 NaN 3
3 NaN 4


.. GENERATED FROM PYTHON SOURCE LINES 26-30 .. code-block:: Python df.groupby("a").sum() .. raw:: html
b
a
1.0 2
10.0 20


.. GENERATED FROM PYTHON SOURCE LINES 31-33 Les valeurs manquantes ont disparu et c'est le comportement attendu Il est possible de corriger le tir avec l'argument `dropna`. .. GENERATED FROM PYTHON SOURCE LINES 33-36 .. code-block:: Python df.groupby("a", dropna=False).sum() .. raw:: html
b
a
1.0 2
10.0 20
NaN 7


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.026 seconds) .. _sphx_glr_download_auto_examples_prog_plot_pandas_groupby.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pandas_groupby.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_pandas_groupby.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_pandas_groupby.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_