File: missing.rst

package info (click to toggle)
pandas 2.2.3%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,784 kB
  • sloc: python: 422,228; ansic: 9,190; sh: 270; xml: 102; makefile: 83
file content (31 lines) | stat: -rw-r--r-- 719 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
In pandas, :meth:`Series.isna` and :meth:`Series.notna` can be used to filter the rows.

.. ipython:: python

   outer_join[outer_join["value_x"].isna()]
   outer_join[outer_join["value_x"].notna()]

pandas provides :ref:`a variety of methods to work with missing data <missing_data>`. Here are some examples:

Drop rows with missing values
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. ipython:: python

   outer_join.dropna()

Forward fill from previous rows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. ipython:: python

   outer_join.ffill()

Replace missing values with a specified value
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using the mean:

.. ipython:: python

   outer_join["value_x"].fillna(outer_join["value_x"].mean())