Skip to content

Commit 83536ae

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

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

pandas/core/frame.py

+46-6
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,11 @@ def lookup(self, row_labels, col_labels):
27142714
col_labels : sequence
27152715
The column labels to use for lookup
27162716
2717+
Returns
2718+
-------
2719+
values : ndarray
2720+
The found values
2721+
27172722
Notes
27182723
-----
27192724
Akin to::
@@ -2722,11 +2727,6 @@ def lookup(self, row_labels, col_labels):
27222727
for row, col in zip(row_labels, col_labels):
27232728
result.append(df.get_value(row, col))
27242729
2725-
Examples
2726-
--------
2727-
values : ndarray
2728-
The found values
2729-
27302730
"""
27312731
n = len(row_labels)
27322732
if n != len(col_labels):
@@ -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)