Skip to content

Commit 58fe4e5

Browse files
committed
DOC: rewrite missing value includes to be more standalone
Now they start with a sentence that sounds like a new paragraph.
1 parent 3526a71 commit 58fe4e5

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

doc/source/getting_started/comparison/comparison_with_sas.rst

+2
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ input frames.
442442
Missing data
443443
------------
444444

445+
Both pandas and SAS have a representation for missing data.
446+
445447
.. include:: includes/missing_intro.rst
446448

447449
One difference is that missing data cannot be compared to its sentinel value.

doc/source/getting_started/comparison/comparison_with_stata.rst

+2
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ or the intersection of the two by using the values created in the
434434
Missing data
435435
------------
436436

437+
Both pandas and State have a representation for missing data.
438+
437439
.. include:: includes/missing_intro.rst
438440

439441
One difference is that missing data cannot be compared to its sentinel value.
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
This doesn't work in pandas. Instead, the :func:`pd.isna` or :func:`pd.notna` functions
2-
should be used for comparisons.
1+
In pandas, :meth:`Series.isna` and :meth:`Series.notna` can be used to filter the rows.
32

43
.. ipython:: python
54
6-
outer_join[pd.isna(outer_join["value_x"])]
7-
outer_join[pd.notna(outer_join["value_x"])]
5+
outer_join[outer_join["value_x"].isna()]
6+
outer_join[outer_join["value_x"].notna()]
87
9-
pandas also provides a variety of methods to work with missing data -- some of
10-
which would be challenging to express in Stata. For example, there are methods to
11-
drop all rows with any missing values, replacing missing values with a specified
12-
value, like the mean, or forward filling from previous rows. See the
13-
:ref:`missing data documentation<missing_data>` for more.
8+
pandas provides :ref:`a variety of methods to work with missing data <missing_data>`. Here are some examples:
9+
10+
Drop rows with missing values
11+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1412

1513
.. ipython:: python
1614
17-
# Drop rows with any missing value
1815
outer_join.dropna()
1916
20-
# Fill forwards
17+
Forward fill from previous rows
18+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19+
20+
.. ipython:: python
21+
2122
outer_join.fillna(method="ffill")
2223
23-
# Impute missing values with the mean
24+
Replace missing values with a specified value
25+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26+
27+
Using the mean:
28+
29+
.. ipython:: python
30+
2431
outer_join["value_x"].fillna(outer_join["value_x"].mean())

doc/source/getting_started/comparison/includes/missing_intro.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Both have a representation for missing data — pandas' is the special float value ``NaN`` (not a
2-
number). Many of the semantics are the same; for example missing data propagates through numeric
3-
operations, and is ignored by default for aggregations.
1+
pandas represents missing data with the special float value ``NaN`` (not a number). Many of the
2+
semantics are the same; for example missing data propagates through numeric operations, and is
3+
ignored by default for aggregations.
44

55
.. ipython:: python
66

0 commit comments

Comments
 (0)