.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "11_demos\python_packages\pandas\demo_missing.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_11_demos_python_packages_pandas_demo_missing.py: Missing data =============== .. GENERATED FROM PYTHON SOURCE LINES 5-13 .. code-block:: Python import pandas as pd import numpy as np dates = pd.date_range("20220501", periods=6) dataFrame = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list("ABCD")) .. GENERATED FROM PYTHON SOURCE LINES 15-16 **Missing data** .. GENERATED FROM PYTHON SOURCE LINES 16-21 .. code-block:: Python dataFrame1 = dataFrame.reindex( index=dates[0:4], columns=list(dataFrame.columns) + ["E"] ) dataFrame1.loc[dates[0] : dates[1], "E"] = 1 .. GENERATED FROM PYTHON SOURCE LINES 22-24 .. code-block:: Python dataFrame1.dropna(how="any") .. raw:: html
A B C D E
2022-05-01 -1.259182 0.667831 -0.197721 0.169983 1.0
2022-05-02 0.629798 1.373583 0.686095 -0.492544 1.0


.. GENERATED FROM PYTHON SOURCE LINES 25-27 .. code-block:: Python dataFrame1.fillna(value=5) .. raw:: html
A B C D E
2022-05-01 -1.259182 0.667831 -0.197721 0.169983 1.0
2022-05-02 0.629798 1.373583 0.686095 -0.492544 1.0
2022-05-03 -0.923828 -0.092225 -0.206072 0.099835 5.0
2022-05-04 0.631935 0.712391 1.455945 0.700102 5.0


.. GENERATED FROM PYTHON SOURCE LINES 28-29 .. code-block:: Python pd.isna(dataFrame1) .. raw:: html
A B C D E
2022-05-01 False False False False False
2022-05-02 False False False False False
2022-05-03 False False False False True
2022-05-04 False False False False True


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.010 seconds) .. _sphx_glr_download_11_demos_python_packages_pandas_demo_missing.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_missing.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_missing.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_missing.zip `