Skip to content

Commit b914f08

Browse files
committed
DOC: DataFrame.dropna doc-string examples
closes pandas-dev#15620
1 parent 4ce9c0c commit b914f08

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

pandas/core/frame.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -3084,6 +3084,46 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,
30843084
Returns
30853085
-------
30863086
dropped : DataFrame
3087+
3088+
Examples
3089+
--------
3090+
>>> df = pd.DataFrame([[np.nan, 2, np.nan, 0], [3, 4, np.nan, 1],
3091+
[np.nan, np.nan, np.nan, 5]],
3092+
columns=list('ABCD'))
3093+
>>> df
3094+
>>> A B C D
3095+
0 NaN 2.0 NaN 0
3096+
1 3.0 4.0 NaN 1
3097+
2 NaN NaN NaN 5
3098+
3099+
Drop the columns where all elements are nan
3100+
>>> df.dropna(axis=1, how='all')
3101+
>>> A B D
3102+
0 NaN 2.0 0
3103+
1 3.0 4.0 1
3104+
2 NaN NaN 5
3105+
3106+
Drop the columns where any of the elements is nan
3107+
>>> df.dropna(axis=1, how='any')
3108+
>>> D
3109+
0 0
3110+
1 1
3111+
2 5
3112+
3113+
Drop the rows where all of the elements is nan
3114+
(there is no row to drop, so df stays the same)
3115+
>>> df.dropna(axis=0, how='all')
3116+
>>> A B C D
3117+
0 NaN 2.0 NaN 0
3118+
1 3.0 4.0 NaN 1
3119+
2 NaN NaN NaN 5
3120+
3121+
Keep only the rows with at least 2 non-na values
3122+
>>> df.dropna(thresh=2)
3123+
>>> A B C D
3124+
0 NaN 2.0 NaN 0
3125+
1 3.0 4.0 NaN 1
3126+
30873127
"""
30883128
inplace = validate_bool_kwarg(inplace, 'inplace')
30893129
if isinstance(axis, (tuple, list)):
@@ -3966,7 +4006,7 @@ def stack(self, level=-1, dropna=True):
39664006
values
39674007
39684008
Examples
3969-
----------
4009+
--------
39704010
>>> s
39714011
a b
39724012
one 1. 2.

0 commit comments

Comments
 (0)