Skip to content

Commit 9bf6b59

Browse files
author
TomAugspurger
committed
DOC: Table about how plots handle missing data.
1 parent 4089cac commit 9bf6b59

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

doc/source/visualization.rst

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,6 @@ To get horizontal bar plots, pass ``kind='barh'``:
203203
@savefig barh_plot_stacked_ex.png
204204
df2.plot(kind='barh', stacked=True);
205205
206-
Pandas tries to be pragmatic about plotting DataFrames or Series
207-
that contain missing data. When it makes sense missing values will
208-
be filled with 0 (as is the case with bar plots). For other plots,
209-
like line plots, filling in 0 usually doesn't make sense, and so pandas doesn't
210-
try to guess. If you want to be explicit you can always call
211-
:meth:`~pandas.DataFrame.fillna` before plotting.
212-
213206
.. _visualization.hist:
214207

215208
Histograms
@@ -684,6 +677,44 @@ See the `matplotlib pie documenation <http://matplotlib.org/api/pyplot_api.html#
684677
685678
plt.close('all')
686679
680+
.. _visualization.missing_data
681+
682+
Plotting with Missing Data
683+
--------------------------
684+
685+
Pandas tries to be pragmatic about plotting DataFrames or Series
686+
that contain missing data. Missing values are dropped, left out, or filled
687+
depending on the plot type.
688+
689+
+----------------+--------------------------------------+
690+
| Plot Type | NaN Handling |
691+
+================+======================================+
692+
| Line | Leave gaps at NaNs |
693+
+----------------+--------------------------------------+
694+
| Line (stacked) | Fill 0's |
695+
+----------------+--------------------------------------+
696+
| Bar | Fill 0's |
697+
+----------------+--------------------------------------+
698+
| Scatter | Drop NaNs |
699+
+----------------+--------------------------------------+
700+
| Histogram | Drop NaNs (column-wise) |
701+
+----------------+--------------------------------------+
702+
| Box | Drop NaNs (column-wise) |
703+
+----------------+--------------------------------------+
704+
| Area | Fill 0's |
705+
+----------------+--------------------------------------+
706+
| KDE | Drop NaNs (column-wise) |
707+
+----------------+--------------------------------------+
708+
| Hexbin | Drop NaNs |
709+
+----------------+--------------------------------------+
710+
| Pie | Fill 0's |
711+
+----------------+--------------------------------------+
712+
713+
If any of these defaults are not what you want, or if you want to be
714+
explicit about how missing values are handled, consider using
715+
:meth:`~pandas.DataFrame.fillna` or :meth:`~pandas.DataFrame.dropna`
716+
before plotting.
717+
687718
.. _visualization.tools:
688719

689720
Plotting Tools

0 commit comments

Comments
 (0)