@@ -2421,7 +2421,7 @@ def _maybe_cast(values, labels=None):
2421
2421
#----------------------------------------------------------------------
2422
2422
# Reindex-based selection methods
2423
2423
2424
- def dropna (self , axis = 0 , how = 'any' , thresh = None , subset = None ):
2424
+ def dropna (self , axis = 0 , how = 'any' , thresh = None , subset = None , inplace = False ):
2425
2425
"""
2426
2426
Return object with labels on given axis omitted where alternately any
2427
2427
or all of the data are missing
@@ -2438,6 +2438,8 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None):
2438
2438
subset : array-like
2439
2439
Labels along other axis to consider, e.g. if you are dropping rows
2440
2440
these would be a list of columns to include
2441
+ inplace : bool, defalt False
2442
+ If True, do operation inplace and return None.
2441
2443
2442
2444
Returns
2443
2445
-------
@@ -2448,31 +2450,36 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None):
2448
2450
for ax in axis :
2449
2451
result = result .dropna (how = how , thresh = thresh ,
2450
2452
subset = subset , axis = ax )
2451
- return result
2452
-
2453
- axis = self ._get_axis_number (axis )
2454
- agg_axis = 1 - axis
2455
-
2456
- agg_obj = self
2457
- if subset is not None :
2458
- agg_axis_name = self ._get_axis_name (agg_axis )
2459
- agg_obj = self .reindex (** {agg_axis_name : subset })
2453
+ else :
2454
+ axis = self ._get_axis_number (axis )
2455
+ agg_axis = 1 - axis
2456
+
2457
+ agg_obj = self
2458
+ if subset is not None :
2459
+ agg_axis_name = self ._get_axis_name (agg_axis )
2460
+ agg_obj = self .reindex (** {agg_axis_name : subset })
2461
+
2462
+ count = agg_obj .count (axis = agg_axis )
2463
+
2464
+ if thresh is not None :
2465
+ mask = count >= thresh
2466
+ elif how == 'any' :
2467
+ mask = count == len (agg_obj ._get_axis (agg_axis ))
2468
+ elif how == 'all' :
2469
+ mask = count > 0
2470
+ else :
2471
+ if how is not None :
2472
+ raise ValueError ('invalid how option: %s' % how )
2473
+ else :
2474
+ raise TypeError ('must specify how or thresh' )
2460
2475
2461
- count = agg_obj . count ( axis = agg_axis )
2476
+ result = self . take ( mask . nonzero ()[ 0 ], axis = axis , convert = False )
2462
2477
2463
- if thresh is not None :
2464
- mask = count >= thresh
2465
- elif how == 'any' :
2466
- mask = count == len (agg_obj ._get_axis (agg_axis ))
2467
- elif how == 'all' :
2468
- mask = count > 0
2478
+ if inplace :
2479
+ self ._update_inplace (result )
2469
2480
else :
2470
- if how is not None :
2471
- raise ValueError ('invalid how option: %s' % how )
2472
- else :
2473
- raise TypeError ('must specify how or thresh' )
2481
+ return result
2474
2482
2475
- return self .take (mask .nonzero ()[0 ], axis = axis , convert = False )
2476
2483
2477
2484
def drop_duplicates (self , cols = None , take_last = False , inplace = False ):
2478
2485
"""
0 commit comments